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 |
|
wisertime
Starting Member
28 Posts |
Posted - 2008-04-11 : 14:55:43
|
| I am only an Admin, not alot of dev experience, so bear with me.I am trying to write a query that pulls data from a table based on a couple fields from another table.I have a table that has a date column and two columns that specify the beg and end of the week for that date (ex. date=4/11, beg=4/6 end=4/12). The table that I need data from has a date column that I could join on.Question: I would like to pull all data from the table between the beg and end dates, which would be for the week before what would be the current date. hope this makes sense, if not no worries, thanks. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-04-11 : 15:08:33
|
| [code]DECLARE @StartDate datetime,@EndDate datetimeSELECT @StartDate=DATEADD(d,-7,beg), @EndDate=DATEADD(d,-7,end)FROM DateTableWHERE date=DATEADD(d,DATEDIFF(d,0,GETDATE()),0)SELECT FieldsFROM DataTableWHERE DateCol BETWEEN @StartDate AND @EndDate[/code] |
 |
|
|
wisertime
Starting Member
28 Posts |
Posted - 2008-04-11 : 15:21:30
|
appreciated.quote: Originally posted by visakh16
DECLARE @StartDate datetime,@EndDate datetimeSELECT @StartDate=DATEADD(d,-7,beg), @EndDate=DATEADD(d,-7,end)FROM DateTableWHERE date=DATEADD(d,DATEDIFF(d,0,GETDATE()),0)SELECT FieldsFROM DataTableWHERE DateCol BETWEEN @StartDate AND @EndDate
|
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-04-11 : 15:26:43
|
quote: Originally posted by wisertime appreciated.quote: Originally posted by visakh16
DECLARE @StartDate datetime,@EndDate datetimeSELECT @StartDate=DATEADD(d,-7,beg), @EndDate=DATEADD(d,-7,end)FROM DateTableWHERE date=DATEADD(d,DATEDIFF(d,0,GETDATE()),0)SELECT FieldsFROM DataTableWHERE DateCol BETWEEN @StartDate AND @EndDate
You're welcome |
 |
|
|
|
|
|
|
|