|
Hi All, What is the best way in sql using datetime format 2012-02-01 00:00:00.000 to select data where on the 1st of the month it returns all data from the previous month i.e. 2012-01-01 00:00:00.000 to 2012-02-01 00:00:00.000, otherwise return data from the 1st of the month to the current date? Thanks for your help! it's a where clause for a report that will be running daily...
(comments are locked)
|
|
First of all you need to realise that date data is not stored in a particular format. It is simply stored as datetime data (actually 8 bytes), and it is only when we read it out of the database does a format get applied. Given that it should be easy to follow that you need a where clause like Hi kev! are you going to sql bits? Can I use an else statement within a where clause so if 1st of month then do first part else do second part?
Feb 29 '12 at 04:07 PM
jhowe
Probably not going to make it :(!
Feb 29 '12 at 04:11 PM
Kev Riley ♦♦
Yea I'll give it a shot! Thanks for your help.
Feb 29 '12 at 04:19 PM
jhowe
Hi Kev can you explain what the second part is doing, datetime functions always confuse the hell out of me...
Mar 01 '12 at 04:38 PM
jhowe
(comments are locked)
|
|
I would have approached it a bit different. I would have applied the logic to the dates in variables before moving to the actual statement i.e.
Then an easy WHERE clause would have been You would need to do the same for the end date too
Mar 01 '12 at 08:11 AM
Kev Riley ♦♦
@Kev Riley Absolutely right :) if the current date has to be included then EndDate should be handled the same way.
Mar 01 '12 at 09:04 AM
Usman Butt
(comments are locked)
|

