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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lbseong
    New Member
    • Sep 2008
    • 7

    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....than k you
  • Delerna
    Recognized Expert Top Contributor
    • Jan 2008
    • 1134

    #2
    Try this
    [code=sql]
    if (SELECT count(DATEDIFF( mI, createdate, getdate())) FROM prontoqueue) > 5
    begin
    Print 'more than 5'
    end
    else
    Print 'less than 5'

    [/code]

    Comment

    • lbseong
      New Member
      • Sep 2008
      • 7

      #3
      this is cool...is working. thanks

      Comment

      Working...