Recent PostsRecent Posts Popular TopicsPopular Topics
 Home Search Members Calendar Who's On

 datediff producing erroneous result when datetime is between midnight and 1AM Rate Topic Display Mode Topic Options
Author
 Message
 Posted Tuesday, October 15, 2013 9:13 PM
 Hall of Fame Group: General Forum Members Last Login: Wednesday, February 24, 2016 6:28 AM Points: 3,977, Visits: 6,431
 `SELECT STUFF(CONVERT(VARCHAR(20),EndDT-StartDT,114),1,2,DATEDIFF(hh,0,EndDT-StartDT))`+1 to Jeff for that! Absolutely brilliant. My mantra: No loops! No CURSORs! No RBAR! Hoo-uh!My thought question: Have you ever been told that your query runs too fast?My advice:INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.Need to UNPIVOT? Why not CROSS APPLY VALUES instead?Since random numbers are too important to be left to chance, let's generate some!Learn to understand recursive CTEs by example.Splitting strings based on patterns can be fast!My temporal SQL musings: Calendar Tables, an Easter SQL, Time Slots and Self-maintaining, Contiguous Effective Dates in Temporal Tables
Post #1505056
 Posted Tuesday, October 15, 2013 9:24 PM
 SSC-Forever Group: General Forum Members Last Login: Today @ 8:26 PM Points: 42,082, Visits: 39,477
 dwain.c (10/15/2013)`SELECT STUFF(CONVERT(VARCHAR(20),EndDT-StartDT,114),1,2,DATEDIFF(hh,0,EndDT-StartDT))`+1 to Jeff for that! Absolutely brilliant.Heh... thanks Dwain but, nah... not brilliant. Just lazy. I hate typing long formulas... I make too many typing mistakes when they get long. --Jeff Moden"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".First step towards the paradigm shift of writing Set Based code: Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column." Helpful Links:How to post code problemsHow to post performance problems
Post #1505059

 Permissions