SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

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

Posting Yak Master

179 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

2872 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

3865 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  
 New 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.05 seconds. Powered By: Snitz Forums 2000