Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,691 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Dear All,
Can some one suggest me to prepare a query for the below sample please ?
Input :
Column1 ,column 2
1,4
1,138
138,2
138,3
Expected output from a query :
Column1,column2,column 3
1,4,NULL
1,138,2
1,138,3
Its like Dividing two columns into 3 based on the numbers on Level values.
Please consider this is like family tree.. grandfather, Father and son data .. but based on two columns like column1 and column2.
Check a query:
select t1.Column1, t1.Column2, t2.Column2
from MyTable t1
left join MyTable t0 on t0.Column2 = t1.Column1
left join MyTable t2 on t2.Column1 = t1.Column2
where t0.Column2 is null