| | |
Accessing a field in SQL
Please support our MS SQL advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2009
Posts: 27
Reputation:
Solved Threads: 0
Hi,
We have schedule a job through SQL agent
in which
We want to access the data of a specific field from SQL table
For example we have a field named interviewDate, we have to compare it with current date.
now we have to write a stored procedure to read the date field.
This is incorrect syntax which we tried(doesn't work)
what will be the syntax to access all the record of interviewdate field.
Later we have to insert that data into another table through a stored procedure.
Thanks !
Pankaj Singh
We have schedule a job through SQL agent
in which
We want to access the data of a specific field from SQL table
For example we have a field named interviewDate, we have to compare it with current date.
now we have to write a stored procedure to read the date field.
This is incorrect syntax which we tried(doesn't work)
sql Syntax (Toggle Plain Text)
CREATE PROCEDURE chkinterview as SELECT * FROM interview if(interviewdate!='2/7/1900 12:00:00 AM') print'ok' ELSE print'not ok'
what will be the syntax to access all the record of interviewdate field.
Later we have to insert that data into another table through a stored procedure.
Thanks !
Pankaj Singh
Last edited by peter_budo; Aug 3rd, 2009 at 11:55 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
First: use code tags when posting your code:
[code=sql]
...query here
[/code]
Secondly: This is an MSSQL question, not an ASP.NET question. The problem here is your query syntax.
Third: The "not equal" operation in MSSQL is <> and not !=. You also need to select one record from your interview table to compare against .. unless you're trying to compare all dates? Please explain what you are doing. Next with DateTimes and interviews you will likely want to have a Start/End date unless all interviews are of a fixed duration. Please clarify.
[code=sql]
...query here
[/code]
Secondly: This is an MSSQL question, not an ASP.NET question. The problem here is your query syntax.
Third: The "not equal" operation in MSSQL is <> and not !=. You also need to select one record from your interview table to compare against .. unless you're trying to compare all dates? Please explain what you are doing. Next with DateTimes and interviews you will likely want to have a Start/End date unless all interviews are of a fixed duration. Please clarify.
sql Syntax (Toggle Plain Text)
CREATE PROCEDURE chkinterview As BEGIN DECLARE @someValue INT IF ((SELECT interviewdate FROM interview WHERE someColumn = @someValue) <> Cast('2/7/1900 12:00:00 AM' as DATETIME)) PRINT 'OK' ELSE PRINT 'NOT OK' END
>> This works for a single row but what if there are multiple rows(6000).
I'm aware and stated that limitation in my original post.
I'm aware and stated that limitation in my original post.
sql Syntax (Toggle Plain Text)
CREATE PROCEDURE chkinterview As BEGIN DECLARE @someValue INT IF EXISTS(SELECT * FROM Interview WHERE InterviewDate = Cast('2/7/1900 12:00:00 AM' as DATETIME)) PRINT 'NOT OK' ELSE PRINT 'OK' END
•
•
Join Date: Jul 2009
Posts: 27
Reputation:
Solved Threads: 0
Hi,
In above code:
If the Condition is true ,so we have to copy the selected column(expr1,expr2,expr3..) into another table.
Can you please explain on this as well.
Thanks
Pankaj Singh
MS SQL Syntax (Toggle Plain Text)
CREATE Procedure chkinterview AS BEGIN Declare @someValue int IF EXISTS(SELECT * FROM Interview WHERE InterviewDate = Cast('2/7/1900 12:00:00 AM' AS datetime)) PRINT 'NOT OK' ELSE PRINT 'OK' END
If the Condition is true ,so we have to copy the selected column(expr1,expr2,expr3..) into another table.
Can you please explain on this as well.
Thanks
Pankaj Singh
Last edited by Ezzaral; Aug 4th, 2009 at 3:37 pm. Reason: Added [code] [/code] tags. Please use them to format any code that you post.
Please use code tags when posting on DaniWeb!
For your question -- Not really. I don't think I understand what you are asking.
"In the above code: If the condition is true" -- means that if the appointment already exists you want to copy it to another table?
For your question -- Not really. I don't think I understand what you are asking.
"In the above code: If the condition is true" -- means that if the appointment already exists you want to copy it to another table?
sql Syntax (Toggle Plain Text)
IF EXISTS(SELECT * FROM Interview WHERE InterviewDate = Cast('2/7/1900 12:00:00 AM' AS DATETIME)) BEGIN INSERT INTO otherTable (col1,col2,col3) SELECT col1,col2,col3 FROM INTERVAL WHERE InterviewDate = Cast('2/7/1900 12:00:00 AM' AS DATETIME) END
Last edited by sknake; Aug 4th, 2009 at 10:07 am.
![]() |
Similar Threads
- Update Binary Field in sql server 2000 (Visual Basic 4 / 5 / 6)
- encrypting a column in sql server 2005 using c# (C#)
- Help-->SQL Statement in vb6 for getting total of Field (Visual Basic 4 / 5 / 6)
- Question about SQL statement (MS SQL)
- Retrieving a field from a SQL procedure (ASP)
- Ms Sql 2000 (MS SQL)
Other Threads in the MS SQL Forum
- Previous Thread: SQL Server question
- Next Thread: Analysis Service SQL Server 2005 Help Please
| Thread Tools | Search this Thread |






