Hi,
In order to retreive all the records with created datetime in last month here is the SQL I use,
Select * from table a where
a.created_dt >= Convert(datetime, convert(char, month(getdate()-day(getdate())))+'/01/'+
convert(char,year(getdate()-day(getdate()))))
and a.created_dt < Convert(datetime, convert(char, month(getdate()))+'/01/'+convert(char,year(getdate())))
[Note: a.created_dt column is a datetime field]
My question is,
IS there any other way to calculate the begin and end of last month. This convert formula gets the query to respond a lot slower compared to substituting the actual date values.
Any help would be greatly appreciated.
In order to retreive all the records with created datetime in last month here is the SQL I use,
Select * from table a where
a.created_dt >= Convert(datetime, convert(char, month(getdate()-day(getdate())))+'/01/'+
convert(char,year(getdate()-day(getdate()))))
and a.created_dt < Convert(datetime, convert(char, month(getdate()))+'/01/'+convert(char,year(getdate())))
[Note: a.created_dt column is a datetime field]
My question is,
IS there any other way to calculate the begin and end of last month. This convert formula gets the query to respond a lot slower compared to substituting the actual date values.
Any help would be greatly appreciated.