I agree with Rob, but wanted to add that you could use a derived table to make the calculations easier.
The basics is what Rob showed with converting the integer to character data then to date using the ISO standard format 112. Since it converts to date from ISO string, this also works as a shorthand.
dateadd(mi, (ppadtm/100*60)+(ppadtm%10
convert(varchar, ppaddt) is same as Rob's convert(char(8), ppaddt) ==> '20090701'
dateadd takes three parameters with first being the interval (e.g., mi or minute); the adjustment amount; then original date. Using the fact that the third parameter takes a date, the ISO string gets converted automatically to a date eliminating the convert(datetime, {value}, 112) showed earlier; however, that would be more explicit approach. Then to keep things as tightly coded as possible, we use the same statement to add in number of minutes decoded as the hours * 60 and minutes from military time as Rob showed.
Hope this helps.
Regards,
--isa
Main Topics
Browse All Topics





by: rob_farleyPosted on 2009-08-26 at 18:42:41ID: 25193907
Don't use User-Defined Functions for this - it will perform very poorly (like I noted on your other question).
har(8),PPA DDT),112), convert(datetime,convert(c har(8),PPD SDT),112)) + 1
har(8),PPA DDT),112), convert(datetime,convert(c har(8),PPD SDT),112)) * 24 + (PPDSTM / 100) - (PPADTM / 100)
har(8),PPA DDT),112), convert(datetime,convert(c har(8),PPD SDT),112)) * 24 * 60 + (PPDSTM / 100) * 60 + (PPDSTM % 100) - (PPDSTM / 100) * 60 - (PPADTM / 100)
Instead, put computed columns on your table (or just query the table using these formulae), that use:
LOSD as datediff(day, convert(datetime,convert(c
(if they leave on the same day, is that one day? If not, remove the +1)
LOSH as datediff(day, convert(datetime,convert(c
LOSM as datediff(day, convert(datetime,convert(c
But you may need to tweak them in case you want to count slightly differently.
Rob