Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

tsql challenge - urgent !!!

$
0
0

Dear experts,

Input

-------

Create  TABLE #tmp(Section CHAR(4),Sno INT,Name VARCHAR(20),Value1 VARCHAR(20),Value2 VARCHAR(20),id INT)

INSERT #tmp VALUES ('sec1',1,'A','1','5',1000)
INSERT #tmp VALUES ('sec1',1,'A','1','10',1000)
INSERT #tmp VALUES ('sec1',1,'B','2','5',1000)
INSERT #tmp VALUES ('sec1',1,'B','2','10',1000)
INSERT #tmp VALUES ('sec1',1,'B','2','15',1000)
INSERT #tmp VALUES ('sec1',2,'C','1','5',1000)
INSERT #tmp VALUES ('sec1',2,'C','1','10',1000)
INSERT #tmp VALUES ('sec1',2,'D','2','5',1000)
INSERT #tmp VALUES ('sec1',2,'D','2','10',1000)
INSERT #tmp VALUES ('sec1',2,'E','3','5',1000)
INSERT #tmp VALUES ('sec1',2,'E','3','10',1000)
INSERT #tmp VALUES ('sec1',2,'E','3','15',1000)
INSERT #tmp VALUES ('sec2',1,'F','1','5',1000)
INSERT #tmp VALUES ('sec2',1,'F','1','10',1000)
INSERT #tmp VALUES ('sec2',1,'F','1','15',1000)
INSERT #tmp VALUES ('sec2',1,'G','2','5',1000)
INSERT #tmp VALUES ('sec2',1,'G','2','10',1000)
INSERT #tmp VALUES ('sec2',2,'H','1','5',1000)
INSERT #tmp VALUES ('sec2',2,'H','1','10',1000)
-----------
INSERT #tmp VALUES ('sec1',1,'A','1','5',1001)
INSERT #tmp VALUES ('sec1',1,'A','1','10',1001)
INSERT #tmp VALUES ('sec1',1,'B','2','5',1001)
INSERT #tmp VALUES ('sec1',1,'B','2','10',1001)
INSERT #tmp VALUES ('sec1',1,'B','2','15',1001)
INSERT #tmp VALUES ('sec1',2,'C','1','5',1001)
INSERT #tmp VALUES ('sec1',2,'C','1','10',1001)
INSERT #tmp VALUES ('sec1',2,'D','2','5',1001)
INSERT #tmp VALUES ('sec1',2,'D','2','10',1001)
INSERT #tmp VALUES ('sec1',2,'E','3','5',1001)
INSERT #tmp VALUES ('sec1',2,'E','3','10',1001)
INSERT #tmp VALUES ('sec1',2,'E','3','15',1001)
INSERT #tmp VALUES ('sec2',1,'F','1','5',1001)
INSERT #tmp VALUES ('sec2',1,'F','1','10',1001)
INSERT #tmp VALUES ('sec2',1,'F','1','15',1001)
INSERT #tmp VALUES ('sec2',1,'G','2','5',1001)
INSERT #tmp VALUES ('sec2',1,'G','2','10',1001)
INSERT #tmp VALUES ('sec2',2,'H','1','5',1001)
INSERT #tmp VALUES ('sec2',2,'H','1','10',1001)

expected results

----------------------

SectionidsnoCol1Col2Col3Col4Col5Col6Col7Col8Col9
sec110001A15B210NULLNULLNULL
sec110001A110B215NULLNULLNULL
sec110002C15D25E310
sec110002C110D210E315
sec210001F110G25NULLNULLNULL
sec210001F115G210NULLNULLNULL
sec210002H15NULLNULLNULLNULLNULLNULL
sec210002H110NULLNULLNULLNULLNULLNULL
sec110011A15B210NULLNULLNULL
sec110011A110B215NULLNULLNULL
sec110012C15D25E310
sec110012C110D210E315
sec210011F110G25NULLNULLNULL
sec210011F115G210NULLNULLNULL
sec210012H15NULLNULLNULLNULLNULLNULL
sec210012H110NULLNULLNULLNULLNULLNULL














































































































































Condition :

for values2 column if more than two values are present then display last two values .




Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>