Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How can I get the dates I need?


How can I get the dates I need?

Author
Message
rick.servant
rick.servant
Grasshopper
Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)

Group: General Forum Members
Points: 13 Visits: 157
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
kevin.l.williams
kevin.l.williams
Hall of Fame
Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)

Group: General Forum Members
Points: 3379 Visits: 1323
I think you might be looking for the DATEDIFF function
http://msdn.microsoft.com/en-us/library/ms189794.aspx



Lynn Pettis
Lynn Pettis
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24255 Visits: 37978
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);

Cool
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)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search