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 |
|
whitmoj
Yak Posting Veteran
68 Posts |
Posted - 2009-01-22 : 03:33:20
|
Good MorningI was wondering if any one can help with the problem I am faced with I currently have a tbl that has the current months data in I have been requested to get the last 6 day of the previous month in there as well. Every thing I have found on the web does not work. If I can add it to my current code it would be great?? My current month code reads WHERE DATEADD(mm,DATEDIFF(mm,0,DC.[Date]),0)=DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0) WhitmojIf I have inspired one person today then my job is done. |
|
|
Jai Krishna
Constraint Violating Yak Guru
333 Posts |
Posted - 2009-01-22 : 04:10:18
|
| Hi Try Thissselect * from urtable where datediff(mm,dc.date,getdate())=0 or datediff(d,dc.date,dateadd(d,-datepart(d,getdate()),getdate()))<6Jai Krishna |
 |
|
|
whitmoj
Yak Posting Veteran
68 Posts |
Posted - 2009-01-22 : 04:22:13
|
| This works great the only issue is in my db where my Date is It goes to 2012 so its returning all my dates. How can I solve this??WhitmojIf I have inspired one person today then my job is done. |
 |
|
|
whitmoj
Yak Posting Veteran
68 Posts |
Posted - 2009-01-22 : 04:24:44
|
| I have sorted it Many thanks JaiJamesWhitmojIf I have inspired one person today then my job is done. |
 |
|
|
Jai Krishna
Constraint Violating Yak Guru
333 Posts |
Posted - 2009-01-22 : 04:29:22
|
| WelcomeJai Krishna |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-01-22 : 04:31:12
|
[code]DECLARE @FromDate DATETIME, @ToDate DATETIMESELECT @FromDate = DATEADD(MONTH, DATEDIFF(MONTH, '19000101', GETDATE()), '18991226'), @ToDate = DATEADD(MONTH, DATEDIFF(MONTH, '19000101', GETDATE()), '19000201')SELECT @FromDate, @ToDateSELECT *FROM Table1WHERE Col1 >= @FromDate AND Col1 < @ToDate[/code] E 12°55'05.63"N 56°04'39.26" |
 |
|
|
|
|
|
|
|