Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 last month-report

Author  Topic 

inbs
Aged Yak Warrior

860 Posts

Posted - 2009-06-03 : 04:44:36
i need to run a report where date>=2007 unitl last moth this year
i mean

where date>=2007 and date<=31.05.09

i mean unitl last day in privious month.

how i write it in sql

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-06-03 : 04:46:43
where date>=1.1.2007 and date<=31.05.09

or

where year(date)>=2007 and date<=31.05.09


Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-06-03 : 04:47:56
where date>='20080101' and date<='20090531'




No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-06-03 : 04:48:40
quote:
Originally posted by webfred

where date>='20070101' and date<='20090531'




No, you're never too old to Yak'n'Roll if you're too young to die.




No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

inbs
Aged Yak Warrior

860 Posts

Posted - 2009-06-03 : 05:27:38
i mean something like that:
last day in privious month

(Cast(DateDiff(Day,0,dateadd(dd, -datepart(dd, GetDate()), GetDate()))As DateTime))
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-03 : 05:36:34
[code]DECLARE @FromDate DATETIME,
@ToDate DATETIME

SELECT @FromDate = DATEADD(YEAR, DATEDIFF(YEAR, '19020101', GETDATE()), '19000101'),
@ToDate = DATEADD(MONTH, DATEDIFF(MONTH, '19000101', GETDATE()), '19000101')

SELECT @FromDate,
@ToDate

SELECT *
FROM Table1
WHERE MyDateCol >= @FromDate
AND MyDateCol < @ToDate[/code]


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-06-03 : 05:41:32
quote:
Originally posted by senthil_nagore

where date>=1.1.2007 and date<=31.05.09

or

where year(date)>=2007 and date<=31.05.09


Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled


It wont work if Server is of mdy format
Peso showed the correct method of doing it

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -