By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,419 Members | 1,609 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,419 IT Pros & Developers. It's quick & easy.

SQL2000- How to use DateDiff Function together with (If then..else)

P: 7
Hi, I am new to this forum please help.

I need to schedule a job to send out an email if found there is a records older than 1 minute (compare to current date time against createddate) and the email will contain the itemid.

mytable design
1.) itemid int
createddate getdatetime()
summaryid varchar
startdate datetime
enddate datetime

this is what i have done

SELECT TOP 1*,DATEDIFF(mI, createdate, getdate()) AS ms
FROM mytable

Can anyone advised on this...
i was also thinking putting in the


set rowcount 1
if (SELECT DATEDIFF(mI, createdate, getdate())FROM prontoqueue) > 5
begin
Print 'more than 5'
end
else
Print 'less than 5'
setrowcount 0



i am hitting an error message...
Server: Msg 512, Level 16, State 1, Line 2
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
less than 5


please advised....thank you
Sep 11 '08 #1
Share this Question
Share on Google+
2 Replies


Delerna
Expert 100+
P: 1,134
Try this
Expand|Select|Wrap|Line Numbers
  1. if (SELECT count(DATEDIFF(mI, createdate, getdate())) FROM prontoqueue) > 5
  2. begin
  3. Print 'more than 5'
  4. end 
  5. else 
  6. Print 'less than 5'
  7.  
  8.  
Sep 11 '08 #2

P: 7
this is cool...is working. thanks
Sep 12 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.