Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I am working on a report that needs to be submitted.I link multiple tables using joinsI narrowed down the problemBasically this is my problemtblSalesR#(salesno) ItemCodeR1 A1 R1 A2 R3 A4R4 A6R7 A7tblPurchase(linked to Sales)R# P#(purchaseno) ItemCodeR1 P1 A1 R1 P2 A2 R4 P5 A6 R3 P3 A4null P6 A8the problem i face when i link isR#(salesno) ItemCode P#R1 A1 P1 R1 A2 P1R1 A1 P2 R1 A2 P2this links twice I want to link both these tables to show all possible situations to show in a report. The result should be something like thisR#(salesno) ItemCode P#R1 A1 P1 R1 A2 P2R3 A4 P3 R4 A6 P5R7 A7 -- A8 P6 Thanks a lot,josh
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts
Posted - 2007-05-31 : 23:30:55
This is illustrated in a confusing way, but I think you want a link on both fields using a outer join
Select coalesce(a.[R#],b.[R#]) as [R#],coalesce(a.[ItemCode],b.[ItemCode])as [ItemCode],coalesce(a.[P#],b.[P#]) as [P#]from tblSales aFull Outer join tblPurchase bon a.[r#] = b.[r#]and a.[ItemCode] = b.[ItemCode]
josh777
Starting Member
12 Posts
Posted - 2007-06-01 : 14:00:08
Hi Vinnie, Thanx for your response. The thing isif i link both fields i am not able to see sales order that do not have a purchase order and using coalesce brings records that i dont need. ( though it does
josh777
Starting Member
12 Posts
Posted - 2007-06-01 : 14:01:18
I figured out ,i did try using two links , it solves the problem ! thanks!