Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Date Diff to show a variable

Author  Topic 

Petronas
Posting Yak Master

134 Posts

Posted - 2011-05-21 : 18:38:56
Hi,

I have to get the following:

If Datediff (getdate(), orderdate) =18 then 'Overdue by (18-5) days
Else if Datediff(getdate(),Orderdate)=16 then 'Overdue by (16-5) days

I don't know how to get the variable.

Appreciate any help in this.

Thanks,
Petronas

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-05-21 : 22:07:03
You can only get the result from one row of the table in a variable

select @v =
case when Datediff(dd,orderdate,getdate()) >=18 then 'Overdue by (18-5) days'
when Datediff(dd,orderdate,getdate()) >=16 then 'Overdue by (16-5) days'
end
from tbl
where orderid = xxx

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Petronas
Posting Yak Master

134 Posts

Posted - 2011-05-22 : 09:38:08
Thank you for for help!

Thanks,
Petronas
Go to Top of Page
   

- Advertisement -