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.
| 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 yeari mean where date>=2007 and date<=31.05.09i 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.09orwhere year(date)>=2007 and date<=31.05.09Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceled |
 |
|
|
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. |
 |
|
|
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. |
 |
|
|
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)) |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-06-03 : 05:36:34
|
[code]DECLARE @FromDate DATETIME, @ToDate DATETIMESELECT @FromDate = DATEADD(YEAR, DATEDIFF(YEAR, '19020101', GETDATE()), '19000101'), @ToDate = DATEADD(MONTH, DATEDIFF(MONTH, '19000101', GETDATE()), '19000101')SELECT @FromDate, @ToDateSELECT *FROM Table1WHERE MyDateCol >= @FromDate AND MyDateCol < @ToDate[/code] E 12°55'05.63"N 56°04'39.26" |
 |
|
|
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.09orwhere year(date)>=2007 and date<=31.05.09Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceled
It wont work if Server is of mdy formatPeso showed the correct method of doing itMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|