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 |
raguyazhin
Posting Yak Master
105 Posts |
Posted - 2012-11-03 : 02:21:12
|
Hi, I am Planning to convert the T-SQL Joins to ANSI Joins But the one of the below query having variation of record counts.kindly suggest me what are the problems in the below queries.--T-SQL Join Query--SELECT * FROM dbo.CL_CLINICAL_MASTER SPM, dbo.CL_ITEM_STOCK_MASTER BID, dbo.CL_ITEM_MASTER IM, dbo.CL_ITEM_CATEGORY UM WHERE SPM.CCM_CLINICAL_CD*= BID.CIS_CLINICAL_CD AND IM.CIM_ITEM_CODE*= BID.CIS_ITEM_CD AND IM.CIM_ITEM_CATEGORY_CD= UM.CIC_CATEGORY_CD --5991 records return--ANSI Join Query--SELECT * FROM CL_CLINICAL_MASTER AS SPM LEFT OUTER JOINCL_ITEM_STOCK_MASTER AS BID ON SPM.CCM_CLINICAL_CD = BID.CIS_CLINICAL_CD RIGHT OUTER JOINCL_ITEM_MASTER AS IM ON BID.CIS_ITEM_CD = IM.CIM_ITEM_CODE INNER JOINCL_ITEM_CATEGORY AS UM ON IM.CIM_ITEM_CATEGORY_CD = UM.CIC_CATEGORY_CD --4684 records return How do i match the ANSI Join Query to T-SQL Join Query.--Ragu |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2012-11-03 : 10:55:13
|
how aboutSELECT * FROM CL_CLINICAL_MASTER AS SPMcross join CL_ITEM_MASTER AS IMjoin CL_ITEM_CATEGORY AS UMon IM.CIM_ITEM_CATEGORY_CD = UM.CIC_CATEGORY_CDLEFT JOIN CL_ITEM_STOCK_MASTER AS BID ON SPM.CCM_CLINICAL_CD = BID.CIS_CLINICAL_CDand IM.CIM_ITEM_CODE = BID.CIS_ITEM_CD==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
Ifor
Aged Yak Warrior
700 Posts |
Posted - 2012-11-05 : 06:59:43
|
or maybe:SELECT *FROM dbo.CL_CLINICAL_MASTER SPM LEFT JOIN dbo.CL_ITEM_STOCK_MASTER BID ON SPM.CCM_CLINICAL_CD = BID.CIS_CLINICAL_CD RIGHT JOIN ( dbo.CL_ITEM_MASTER IM JOIN dbo.CL_ITEM_CATEGORY UM ON IM.CIM_ITEM_CATEGORY_CD = UM.CIC_CATEGORY_CD ) ON BID.CIS_ITEM_CD = IM.CIM_ITEM_CODE The thing to remember with the *=/=* syntax is that the * is against the table where all the rows are preserved. |
|
|
|
|
|