Click here to Skip to main content
15,908,254 members
Home / Discussions / Database
   

Database

 
GeneralWorking with just time section of a datetime type Pin
Den2Fly4-Nov-04 21:56
Den2Fly4-Nov-04 21:56 
GeneralRe: Working with just time section of a datetime type Pin
Colin Angus Mackay4-Nov-04 22:14
Colin Angus Mackay4-Nov-04 22:14 
GeneralRe: Working with just time section of a datetime type Pin
Den2Fly7-Nov-04 1:45
Den2Fly7-Nov-04 1:45 
GeneralRe: Working with just time section of a datetime type Pin
Colin Angus Mackay7-Nov-04 1:53
Colin Angus Mackay7-Nov-04 1:53 
GeneralRe: Working with just time section of a datetime type Pin
Grimolfr5-Nov-04 9:39
Grimolfr5-Nov-04 9:39 
GeneralRe: Working with just time section of a datetime type Pin
Jon Rista5-Nov-04 10:53
Jon Rista5-Nov-04 10:53 
GeneralRe: Working with just time section of a datetime type Pin
Den2Fly7-Nov-04 1:48
Den2Fly7-Nov-04 1:48 
GeneralRe: Working with just time section of a datetime type Pin
Grimolfr7-Nov-04 4:51
Grimolfr7-Nov-04 4:51 
As Colin indicated in his original response, usability and efficiency both depend greatly on exactly what you're doing with it.

Also, I've found that when you take two solutions to the same problem and compare them, it's possible that one solution is faster on one server, and the other is faster on a different one.

For instance, stripping the time from a datetime. There are many ways to do this, the two most common being CONVERT(varchar(8), theDate, 112) or DATEADD(day, 0, DATEDIFF(day, 0, theDate)). I find that DATEADD/DATEDIFF runs faster in our development environment by a factor of 5, but the CONVERT method is faster in our production environment by a factor of 2.

So, the short answer is that you should write the query both ways, and benchmark them on your own system to see which one is faster on your own server. It also depends greatly on where/how you're using it. If you're using it in the WHERE clause, either one of them is going to be a pig. If you're just using it in the SELECT clause, then it will probably depend on your system hardware and configuration.


Grim
(aka Toby)
MCDBA, MCSD, MCP+SB


SELECT * FROM user WHERE clue IS NOT NULL
GO
(0 row(s) affected)

GeneralRe: Working with just time section of a datetime type Pin
Den2Fly7-Nov-04 20:02
Den2Fly7-Nov-04 20:02 
GeneralNsted SELECT statements Pin
Den2Fly4-Nov-04 12:02
Den2Fly4-Nov-04 12:02 
GeneralRe: Nsted SELECT statements Pin
Christian Graus4-Nov-04 12:17
protectorChristian Graus4-Nov-04 12:17 
GeneralRe: Nsted SELECT statements Pin
Den2Fly4-Nov-04 21:20
Den2Fly4-Nov-04 21:20 
GeneralRe: Nsted SELECT statements Pin
Christian Graus4-Nov-04 21:23
protectorChristian Graus4-Nov-04 21:23 
GeneralRe: Nsted SELECT statements Pin
Colin Angus Mackay4-Nov-04 22:11
Colin Angus Mackay4-Nov-04 22:11 
GeneralRe: Nsted SELECT statements Pin
Christian Graus4-Nov-04 22:16
protectorChristian Graus4-Nov-04 22:16 
GeneralRe: Nsted SELECT statements Pin
munawarhussain9-Nov-04 6:18
munawarhussain9-Nov-04 6:18 
GeneralRe: Nsted SELECT statements Pin
Christian Graus9-Nov-04 8:44
protectorChristian Graus9-Nov-04 8:44 
GeneralRe: Nsted SELECT statements Pin
munawarhussain11-Nov-04 9:03
munawarhussain11-Nov-04 9:03 
GeneralRe: Nsted SELECT statements Pin
Christian Graus11-Nov-04 9:05
protectorChristian Graus11-Nov-04 9:05 
GeneralRe: Nsted SELECT statements Pin
Colin Angus Mackay4-Nov-04 20:29
Colin Angus Mackay4-Nov-04 20:29 
GeneralRe: Nsted SELECT statements Pin
Den2Fly4-Nov-04 21:25
Den2Fly4-Nov-04 21:25 
GeneralRe: Nsted SELECT statements Pin
Christian Graus4-Nov-04 22:19
protectorChristian Graus4-Nov-04 22:19 
GeneralCall multiple stored procs in the same query Pin
Luis Alonso Ramos4-Nov-04 7:12
Luis Alonso Ramos4-Nov-04 7:12 
GeneralRe: Call multiple stored procs in the same query Pin
Christian Graus4-Nov-04 12:30
protectorChristian Graus4-Nov-04 12:30 
GeneralJOIN with optional field Pin
Luis Alonso Ramos4-Nov-04 6:33
Luis Alonso Ramos4-Nov-04 6:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.