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 |
|
brucezepplin
Starting Member
15 Posts |
Posted - 2011-07-06 : 04:55:28
|
| Hi there, I have two tables, each having a date column where an event took place. I am looking for an sql statement where I pull out a date from the first table, and then bring all dates out from the second table that is plus or minus 10 days from the date in the first table.so something like:GROUP BY A.DATE, B.DATEHAVING/WHERE B.DATE +/- A.DATEapologies, but I have never really had to work with comparing daes before. thanks. |
|
|
Ranjit.ileni
Posting Yak Master
183 Posts |
Posted - 2011-07-06 : 04:59:31
|
| select abs(datediff(day,(getdate()+10),getdate())) ---10select abs(datediff(day,getdate(),(getdate()+10))) ---10--Ranjit |
 |
|
|
Ranjit.ileni
Posting Yak Master
183 Posts |
Posted - 2011-07-06 : 05:05:43
|
| declare @Table table(id int,startDate Datetime,endDate Datetime)insert @Tableselect 1,getdate(),getdate()+10 union allselect 2,getdate(),getdate()-10 union allselect 3,getdate(),getdate()+9 select * from @Tablewhere abs(datediff(day,startDate,endDate))=10--Ranjit |
 |
|
|
brucezepplin
Starting Member
15 Posts |
Posted - 2011-07-06 : 05:22:19
|
| thanks ranjit. can i use A.EVENT,B.EVENT as parameters in the DATEDIFF function?ie abs(datediff(day,A.EVENT,B.EVENT))=10 ? |
 |
|
|
Ranjit.ileni
Posting Yak Master
183 Posts |
Posted - 2011-07-06 : 05:27:42
|
| Yes You can Use--Ranjit |
 |
|
|
|
|
|
|
|