Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function inside quotes 1

Status
Not open for further replies.

chrissparkle

Programmer
Mar 27, 2006
50
NZ
I have this line of code in a proc:

Code:
 CASE WHEN DATEDIFF(n, mbx.date_received, GETDATE()) BETWEEN 0 AND 10 THEN 'DATEDIFF(n, mbx.date_received, GETDATE()) min ago' END as USE_DATE

How can I get the DateDiff function to output the actual value when inside quotes? At the moment it just outputs the raw sql??
 
Try this...

Code:
[COLOR=blue]CASE[/color] [COLOR=blue]WHEN[/color] [COLOR=#FF00FF]DATEDIFF[/color](n, mbx.date_received, [COLOR=#FF00FF]GETDATE[/color]()) BETWEEN 0 AND 10 
     [COLOR=blue]THEN[/color] [COLOR=#FF00FF]Convert[/color]([COLOR=blue]VarChar[/color](20), [COLOR=#FF00FF]DATEDIFF[/color](n, mbx.date_received, [COLOR=#FF00FF]GETDATE[/color]())) + [COLOR=red]' min ago'[/color]
     [COLOR=blue]END[/color] [COLOR=blue]as[/color] USE_DATE

DateDiff always returns an integer, so you need to convert that integer to a varchar and append it to your ' min ago' string.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top