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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Where lause with case
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

181 Posts

Posted - 01/20/2013 :  13:59:15  Show Profile  Reply with Quote
Declare @date datetime = '31/12/2012'

Table 1 has a datetime field called pDate

what I want to do is select all records from table 1 where
pdate = @date or Pdate = @date + 1 day or Pdate = @date + 2

Flowing Fount of Yak Knowledge

2875 Posts

Posted - 01/20/2013 :  17:07:32  Show Profile  Reply with Quote
FROM Table1
WHERE pDate >= @date and pDate <= DATEADD(day,2,@date)


Everyday I learn something that somebody else already knew
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 01/20/2013 :  18:24:35  Show Profile  Reply with Quote
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:
FROM Table1
WHERE pDate >= @date and pDate < DATEADD(day,3,@date)

Edited by - James K on 01/20/2013 18:27:20
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000