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)

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

sknake commented: You have been here long enough to know about code tags -1

Recommended Answers

All 5 Replies

First: use code tags when posting your 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.

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). Do we have a loop for that.
Then
We have to copy the whole row into another table.
Can you please explain on this as well.
Thanks
Pankaj Singh

>> 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.

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

Hi,

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

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

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?

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.