I want to format SQL result in to given format in SQL Server -


sql result:

id student_name class ---------------------- 1  abc          1a   2  xyz          1a  3  dsk          1a 4  uij          1a .................  ................. ................. ................. ................. 1000 results 

i want format data in specific format

id1 student_name1 class1 id2 student_name2 class2 id3 student_name3 class3 ----------------------------------------------------------------------------------- 1  abc             1a     2  abc            1a    3  abc          1a  4  abc             1a     5  abc            1a    6  abc          1a 7  abc             1a    

as comment says, question isn't clear, wrote query think need ... try out , let me know if wanted

if object_id('tempdb..#temp') not null drop table #temp create table #temp (id int, student_name nvarchar(100), class nvarchar(10))  insert #temp (id, student_name, class) values (1, 'abc', '1a'), (2, 'xyz', '1a'), (3, 'dsk', '1a'), (4, 'uij', '1a'), (5, 'sss', '1a'), (6, 'fff', '1a'), (7, 'ccc', '1a')  select t1.id [id1],     t1.student_name [student_name1],    t1.class [class1],    t2.id [id2],     t2.student_name [student_name2],    t2.class [class2],    t3.id [id3],     t3.student_name [student_name3],    t3.class [class3] #temp t1 left join #temp t2 on t1.id + 1 = t2.id left join #temp t3 on t1.id + 2 = t3.id (t1.id - 1) % 3 = 0 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -