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 |
Pete_N
Posting Yak Master
181 Posts |
Posted - 2013-01-20 : 13:59:15
|
Declare @date datetime = '31/12/2012'Table 1 has a datetime field called pDatewhat I want to do is select all records from table 1 wherepdate = @date or Pdate = @date + 1 day or Pdate = @date + 2 |
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2013-01-20 : 17:07:32
|
SELECT *FROM Table1WHERE pDate >= @date and pDate <= DATEADD(day,2,@date)JimEveryday I learn something that somebody else already knew |
|
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-01-20 : 18:24:35
|
Based on your description, what Jim suggested would be the right thing to do. But, if the pdate field has a time portion to it also, and if your @date is always only date, and if you want to retrieve all the data for the 3 days (including those happen during the day on T+2) as well, then you may want to use:SELECT *FROM Table1WHERE pDate >= @date and pDate < DATEADD(day,3,@date) |
|
|
|
|
|