Click here to Skip to main content
16,005,206 members
Home / Discussions / Database
   

Database

 
AnswerRe: Group by date Pin
Kschuler22-May-06 3:36
Kschuler22-May-06 3:36 
GeneralRe: Group by date Pin
Sasuko22-May-06 3:49
Sasuko22-May-06 3:49 
GeneralRe: Group by date Pin
Kschuler22-May-06 4:24
Kschuler22-May-06 4:24 
AnswerRe: Group by date Pin
Colin Angus Mackay22-May-06 5:21
Colin Angus Mackay22-May-06 5:21 
AnswerRe: Group by date Pin
Eric Dahlvang22-May-06 8:40
Eric Dahlvang22-May-06 8:40 
GeneralRe: Group by date Pin
Colin Angus Mackay22-May-06 11:28
Colin Angus Mackay22-May-06 11:28 
QuestionRe: Group by date Pin
Eric Dahlvang22-May-06 11:38
Eric Dahlvang22-May-06 11:38 
AnswerRe: Group by date Pin
Colin Angus Mackay22-May-06 12:10
Colin Angus Mackay22-May-06 12:10 
If the [date] column in the database contains no time elements then, say, 22-May-2006 would be stored as midnight (00:00:00). In that case you wouldn't need to do the 23:59:59 (or 23:59 on a SMALLDATETIME) thing.

It has confused me why there isn't a useful built-in date only function (to extract just the date part) for comparisons such as this.

Solutions I've used in the past include:
-- Performance is okay
...WHERE DAY([date]) = 22 AND MONTH([date]) = 5 AND YEAR([date]) = 2006
 
-- Performance is abysmal on large datasets and useless if part of a join (What was I thinking!?!)
WHERE [date] = dbo.datetime_rounddown(@someDateTime) 
 
-- Okay as a replacement for a column that is being SELECTed
SELECT dbo.datetime_rounddown([date]) FROM MyTable
 
-- If using a temp table to add an extra column that specifically excluded the time portion

-- Or if the table is sufficiently large, you could add an extra column to hold the date only version


I've never tried to convert it to an varchar and use that so I don't know what the performance is like, but it would have to be the ISO format because greater/less-than comparisons wouldn't work properly, e.g. (using the British format)
22/05/2006
22/05/2007 -- Jump a year
23/05/2005 -- then jump almost two years back again.

You'd get a similar situation with the US format date too.

If the comparison is something that is going to be done a lot and the table is large, then it may be worth considering denormalising the data model slightly to boost the performance. I've done that before where the table was holding millions of rows. Some queries went from taking several minutes to taking a few seconds.


"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)

My: Website | Blog
QuestionSQL 2000 Reporting Services - HTTP Error 403 Pin
Kevin McFarlane22-May-06 3:16
Kevin McFarlane22-May-06 3:16 
AnswerRe: SQL 2000 Reporting Services - HTTP Error 403 Pin
Paul Conrad22-May-06 6:13
professionalPaul Conrad22-May-06 6:13 
GeneralRe: SQL 2000 Reporting Services - HTTP Error 403 Pin
Kevin McFarlane22-May-06 23:31
Kevin McFarlane22-May-06 23:31 
AnswerRe: SQL 2000 Reporting Services - HTTP Error 403 Pin
Kevin McFarlane23-May-06 5:48
Kevin McFarlane23-May-06 5:48 
QuestionSelect QUERY from a collection Pin
NICE TO MEET22-May-06 3:04
NICE TO MEET22-May-06 3:04 
AnswerRe: Select QUERY from a collection Pin
Paul Brower22-May-06 10:11
Paul Brower22-May-06 10:11 
QuestionDeadlock in the MS Sql server 2000 Pin
srinivasaRaoS22-May-06 0:51
srinivasaRaoS22-May-06 0:51 
AnswerRe: Deadlock in the MS Sql server 2000 Pin
Colin Angus Mackay22-May-06 1:32
Colin Angus Mackay22-May-06 1:32 
GeneralRe: Deadlock in the MS Sql server 2000 Pin
srinivasaRaoS29-May-06 2:05
srinivasaRaoS29-May-06 2:05 
GeneralRe: Deadlock in the MS Sql server 2000 Pin
Colin Angus Mackay29-May-06 4:47
Colin Angus Mackay29-May-06 4:47 
GeneralRe: Deadlock in the MS Sql server 2000 Pin
srinivasaRaoS29-May-06 23:48
srinivasaRaoS29-May-06 23:48 
GeneralRe: Deadlock in the MS Sql server 2000 Pin
Colin Angus Mackay30-May-06 12:06
Colin Angus Mackay30-May-06 12:06 
Questiondata binding Pin
maaran21-May-06 23:33
maaran21-May-06 23:33 
AnswerRe: data binding Pin
Frank Kerrigan22-May-06 4:03
Frank Kerrigan22-May-06 4:03 
QuestionIndex seek and Index scan Pin
dayakar_dn21-May-06 23:15
dayakar_dn21-May-06 23:15 
AnswerRe: Index seek and Index scan Pin
woudwijk21-May-06 23:36
woudwijk21-May-06 23:36 
QuestionLooking for MS Access articles Pin
John R. Shaw21-May-06 9:47
John R. Shaw21-May-06 9:47 

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.