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 |
|
barnabeck
Posting Yak Master
236 Posts |
Posted - 2010-06-17 : 07:12:01
|
| I tried everything I know, but the tables won't join the way I want them to join:Table_A Table_B-------- --------DATE CALENDAR18.6.2010 17.6.201018.6.2010 18.6.201019.6.2010 19.6.201021.6.2010 20.6.201021.6.2010 21.6.2010I want ALL records from Table_A plus those records from Table_B with Calendar-dates that haven't any match in Table_A.(17.6.2010 & 20.6.2010)Select CASE WHEN Table_A.DATE IS NULL THEN Table_B.CALENDAR ELSE Table_A.DATE AS ALLDATEThe WHERE CLAUSE specifies those records in a 2 weeks period.WHERE ALLDATE BETWEEN GETDATE() AND GETDATE()+13 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-06-17 : 07:28:24
|
select * from(select Date as ALLDATE from Table_Aunion allselect CALENDAR from Table_B where not exists(select * from Table_A where Table_A.Date = Table_B.CALENDAR))dtWHERE ALLDATE BETWEEN GETDATE() AND GETDATE()+13 No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
barnabeck
Posting Yak Master
236 Posts |
Posted - 2010-06-18 : 06:22:11
|
| Thanks!!!Helped a lot and taught even more as I adapted it to my query!Martin |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-06-18 : 09:57:55
|
welcome  No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|