Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How can I get the dates I need? Expand / Collapse
Author
Message
Posted Friday, May 10, 2013 4:23 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, August 11, 2014 10:25 AM
Points: 5, Visits: 85
date1 >= 01/01/2013 --@STARTDATE
date1 <= 02/28/2013 --@ENDDATE

columns:
quote# date1 date2
1 01/01/2013 12/21/2012 <----This date is within -30 days of date1
2 02/17/2013 01/25/2013 <----This date is within -30 days of date1
3 02/08/2013 11/03/2012 <----This date is not within -30 days of date1
I do not want to return this row.


I only want to return a row if the date2 column is within -30 days of date1
Post #1451775
Posted Friday, May 10, 2013 4:32 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: 2 days ago @ 8:30 AM
Points: 3,142, Visits: 1,261
I think you might be looking for the DATEDIFF function
http://msdn.microsoft.com/en-us/library/ms189794.aspx



Post #1451776
Posted Friday, May 10, 2013 4:56 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 4:56 PM
Points: 23,400, Visits: 32,256
rick.servant (5/10/2013)
date1 >= 01/01/2013 --@STARTDATE
date1 <= 02/28/2013 --@ENDDATE

columns:
quote# date1 date2
1 01/01/2013 12/21/2012 <----This date is within -30 days of date1
2 02/17/2013 01/25/2013 <----This date is within -30 days of date1
3 02/08/2013 11/03/2012 <----This date is not within -30 days of date1
I do not want to return this row.


I only want to return a row if the date2 column is within -30 days of date1


Give this a try:

select * from dbo.QuoteData where date2 >= dateadd(dd, -30, date1);



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1451781
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse