By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
Declare @table table
(Name Varchar(10),
Cnt INT,
Vol INT,
Descc VARCHAR(10))
INSERT INTO @table(Name,cnt,vol,Descc)values ('Mohan',21,8,'Fed')
INSERT INTO @table(Name,cnt,vol,Descc)values ('Mohan',1,391,'Fed:::')
select Name, max(case when seq = 1 then Cnt end) as cnt1,
max(case when seq = 1 then Vol end) as Vol1,
max(case when seq = 1 then Descc end) as Descc1,
max(case when seq = 2 then Cnt end) as cnt2,
max(case when seq = 2 then Vol end) as Vol2,
max(case when seq = 2 then Descc end) as Descc2
from (select t.*, row_number() over (partition by name order by (select 1 )) as seq
from @table t
) t
group by Name;
Name | cnt1 | Vol1 | Descc1 | cnt2 | Vol2 | Descc2 |
---|---|---|---|---|---|---|
Mohan | 21 | 8 | Fed | 1 | 391 | Fed::: |
Warning: Null value is eliminated by an aggregate or other SET operation.