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 |
|
Ancy
Starting Member
23 Posts |
Posted - 2010-09-24 : 06:22:46
|
| Hi I have a stored procedre that needs to be upgraded from SQL 2000 to sql 2008. One of te queries had to be changed from "*=" syntax to left outer join syntax for the upgradation . However after making the changes, the results are differing between the two queriesSQL 2000 Queryselect u.U_DED,k.K_DED,um.NEXT_AMOUNT,km.NEXT_AMOUNT,yk.YTD_K_DED, yk.YTD_K_DED * .4 YTD_MATCHfrom #HOUR h,#401U u,#401K k,#401U_MATCH um,#401K_MATCH km,#YTD_K ykwhere h.EMPLOYEE *= um.EMPLOYEEand h.EMPLOYEE *= km.EMPLOYEE and h.EMPLOYEE *= u.EMPLOYEEand h.EMPLOYEE = k.EMPLOYEEand h.EMPLOYEE *= yk.EMPLOYEEand (um.NEXT_AMOUNT <> 0 and km.NEXT_AMOUNT <> 0 and u.U_DED <> 0 and k.K_DED <> 0)Result------U_DED K_DED NEXT_AMOUNT NEXT_AMOUNT YTD_K_DED YTD_MATCH----- ----- ----------- ----------- --------- --------- NULL 20.00 NULL NULL 20.00 8.000SQL 2008 Queryselect u.U_DED,k.K_DED,um.NEXT_AMOUNT,km.NEXT_AMOUNT,yk.YTD_K_DED, yk.YTD_K_DED * .4 YTD_MATCHfrom #HOUR hLEFT OUTER JOIN #401U_MATCH um ON h.EMPLOYEE = um.EMPLOYEELEFT OUTER JOIN #401K_MATCH km ON h.EMPLOYEE = km.EMPLOYEELEFT OUTER JOIN #401U u ON h.EMPLOYEE = u.EMPLOYEEJOIN #401K k ON h.EMPLOYEE = k.EMPLOYEELEFT OUTER JOIN #YTD_K yk ON h.EMPLOYEE = yk.EMPLOYEEand (um.NEXT_AMOUNT <> 0 and km.NEXT_AMOUNT <> 0 and u.U_DED <> 0 and k.K_DED <> 0)ResultU_DED K_DED NEXT_AMOUNT NEXT_AMOUNT YTD_K_DED YTD_MATCH----- ----- ----------- ----------- --------- --------- NULL 20.00 NULL NULL NULL NULLHow can I get the same result as the sql 2000 query in sql 2008?ThanksAncy |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-09-24 : 06:30:01
|
your last line " and (um.Next_Amount ...)"has to be " WHERE (um.Next_Amount ...)"because it is NOT a part of an ON Clause. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
Ancy
Starting Member
23 Posts |
Posted - 2010-09-24 : 06:44:15
|
| Hi thanks for the reply but if i add it as a part of the where clause, the whole result record is eliminated.I have found the solution though.. the sql 2008 query should beselect u.U_DED,k.K_DED,um.NEXT_AMOUNT,km.NEXT_AMOUNT, yk.YTD_K_DED, yk.YTD_K_DED * .4 YTD_MATCHfrom #HOUR hLEFT OUTER JOIN #401U_MATCH um ON h.EMPLOYEE = um.EMPLOYEEJOIN #401K k ON h.EMPLOYEE = k.EMPLOYEELEFT OUTER JOIN #401K_MATCH km ON h.EMPLOYEE = km.EMPLOYEELEFT OUTER JOIN #401U u ON h.EMPLOYEE = u.EMPLOYEEand u.U_DED <> 0 and k.K_DED <> 0and um.NEXT_AMOUNT <> 0 and km.NEXT_AMOUNT <> 0 LEFT OUTER JOIN #YTD_K yk ON h.EMPLOYEE = yk.EMPLOYEE had to do with the order of execution |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-09-24 : 06:44:51
|
| I think those individual tests for <> 0 need to be put in the JOIN for each table that they refer to - otherwise they will force an inner join.Surprised it ever worked the "old way"!! |
 |
|
|
Ancy
Starting Member
23 Posts |
Posted - 2010-09-24 : 07:56:25
|
| Thanks for pointing it out...That seems to be the proper way of doing it |
 |
|
|
|
|
|
|
|