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 |
|
WoodHouse
Posting Yak Master
211 Posts |
Posted - 2010-04-16 : 06:13:58
|
| Hi So I have two simple tables (as below). Sales table: sale_date sale_amount---------- -----------2009-01-01 120.502009-01-02 115.002009-01-03 140.802009-01-04 100.50 Calendar table:calendar_date holiday_name------------- ----------------2009-01-01 New Year's Day2009-01-02 NULL2009-01-03 NULL2009-01-04 NULL2009-01-05 NULL To retrieve sales data for holiday dates, I write the query as SELECT sale_date, sale_amountFROM Sales AS SWHERE sale_date IN (SELECT sale_date FROM Calendar AS C WHERE holiday_name IS NOT NULL) Can you guess what will be the outcome of the above query and WHY(this is the important part!!)??? |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-04-16 : 06:33:16
|
| Outcome:- Will cause a execution time error.WHY :- Because there is no sale_date column in calendar table.PBUH |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-04-16 : 07:12:36
|
Assuming you would like to use calendar_date in your subquery and the date are always stored without time part.Out put would be2009-01-01 120.50 Why?Your subselect returns '2009-01-01' because that is the only record with holiday_name IS NOT NULL.So your query looks like this SELECT sale_date, sale_amountFROM Sales AS SWHERE sale_date IN (2009-01-01) No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|