467,915 Members | 1,270 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,915 developers. It's quick & easy.

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

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
  • viewed: 2424
Share:
2 Replies
Delerna
Expert 1GB
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
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.

Similar topics

5 posts views Thread by mcbill20 | last post: by
2 posts views Thread by Derrick | last post: by
14 posts views Thread by cmdolcet69 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.