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 have tab1 as:Col1 Col2 Col31 2 NullThen the Master as:Col Name1 One2 Two3 ThreeI want the output as Col1 Col2 Col3One Two NullAny help? I have been struggling since yesterday.
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2008-01-04 : 11:46:07
[code]SELECT t2.Name AS 'Col1', t3.Name AS 'Col2', t4.Name AS 'Col3'FROM tab1 t1OUTER APPLY ( SELECT Name FROM Master WHERE Col=t1.Col1)t2OUTER APPLY ( SELECT Name FROM Master WHERE Col=t1.Col2)t3OUTER APPLY ( SELECT Name FROM Master WHERE Col=t1.Col3)t4[/code]
munishk
Starting Member
3 Posts
Posted - 2008-01-05 : 04:31:17
I think APPLY operator works only in SQL Server 2005.I am working on SQL Server 2000. Forgot to mention that in my previous post.Can you suggest a solution for SQL 2000?
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2008-01-05 : 06:59:21
Try this then :-
SELECT t2.[Name] AS 'Col1', t3.[Name] AS 'Col2', t4.[Name] AS 'Col3'FROM tab1 t1LEFT OUTER JOIN ( SELECT Col,[Name] FROM Master )t2ON t2.Col=t1.Col1LEFT OUTER JOIN ( SELECT Col,[Name] FROM Master )t3ON t3.Col=t1.Col2LEFT OUTER JOIN ( SELECT Col,[Name] FROM Master )t4ON t4.Col=t1.Col3