samedi 2 juillet 2016

DATEDIFF/Case statement

Please see the below query (This is part of a longer code that I need to edit)

select 'Admit '+cast **(DATEDIFF(day,(case when Sc.AppointmentDateTime is null then Ws.EndTime else Sc.AppointmentDateTime end),sp.AdmissionDateTime) as varchar)+' day(s) later; ' AS 'data()'**
from WHREPORTING.APC.Spell sp
where sp.AdmissionDate>='01 jan 2016'

Now I believe the part in bold brings out the DATEDIFF of the 2 dates as a figure. The output looks like this..

"Admit 1 day(s) later; "

What I am trying to do is somehow make the output specify whether it is 1-2 days later, or 2-14 days later. if that makes sense? So if the figure is 5 it would say "Admit 2-14 days later"

Would I need another case statement nested in there somehow?

I really appreciate any help.

Aucun commentaire:

Enregistrer un commentaire