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 |
|
Vaishu
Posting Yak Master
178 Posts |
Posted - 2011-02-22 : 11:22:03
|
| Help me to get ALL ROWS FROM TblconPRc and unmatched rows from TblDEFPRc. So the result will be like below. PLIST and ITEMCODE have same data on both table. NOTE: The whole idea is if the customer have price available in TblconPRc then that price should show up, else the price from TblDEFPRc. Also I need to INDEX this view, so not able to use UNION operator. Any help getting around this to create INDEXED VIEWEXPECTED RESULT IS : PLIST----ITEMCODE----CALPRICESAM-------123WER------1.25TAS-------FUJ345------1.78SAM-------FUJ345------1.45MAN-------123WER------1.35 -------Top 4 rows from TblconPRc---TAS-------SON567------4.55 -------below 2 rows from TblDEFPRc---COL-------123WER------1.55TblconPRcPLIST----ITEMCODE----FPRICESAM-------123WER------1.25TAS-------FUJ345------1.78SAM-------FUJ345------1.45MAN-------123WER------1.35TblDEFPRcPLIST----ITEMCODE----UNITPRCTAS-------SON567------4.55 - unmatched rowCOL-------123WER------1.55 - unmatched rowSAM-------123WER------1.55 -match with TblconPRc by PLIST & ITEMCODETAS-------FUJ345------1.98 -match with TblconPRc by PLIST & ITEMCODESAM-------FUJ345------1.65 -match with TblconPRc by PLIST & ITEMCODEMAN-------123WER------1.75 --match with TblconPRc by PLIST & ITEMCODEI have got the answer in this forum as below and its works BUT IT USE UNION. ANY IDEA TO GET SAME RESULT WITHOUT USING UNION;with cte as(select PLIST, ITEMCODE, FPRICEfrom #TblconPRc union allselect t2.PLIST,t2.ITEMCODE,t2.UNITPRCfrom #TblconPRc t1right join #TblDEFPRc t2 on t1.PLIST=t2.PLIST and t1.ITEMCODE=t2.ITEMCODEwhere t1.PLIST is null and t1.ITEMCODE is null)select PLIST,ITEMCODE,FPRICE as CALPRICE from cteResult:PLIST ITEMCODE CALPRICESAM 123WER 1.25TAS FUJ345 1.78SAM FUJ345 1.45MAN 123WER 1.35TAS SON567 4.55COL 123WER 1.55 |
|
|
|
|
|