0

I have the a table as follows:

Name LOSSAMT LOSSTYPE
ABC 100. A.
PQR. 200. B.

I want to write a query which can give the following result:

Name Losstype A amt LOSSTYPE B amt
ABC 100 0
PQR. 0 200
Zhorov
  • 28,486
  • 6
  • 27
  • 52
Akash Joshi
  • 1,099
  • 1
  • 9
  • 13

1 Answers1

0

Try this

  declare @tb1 table ([Name] varchar(200), [LOSSAMT] int , [LOSSTYPE] varchar(20) );

insert into @tb1 ([Name], [LOSSAMT], [LOSSTYPE])
values
('ABC', 100., 'A'),
('PQR.', 200, 'B');

Select Name,
       Case When LOSSTYPE = 'A' Then LOSSAMT
       else 0 end as [LOSSTYPE A amt],
       Case When LOSSTYPE = 'B' Then LOSSAMT
       else 0 end as [LOSSTYPE B amt]
From @tb1

If this is not the way you looking for, let me know.

Shu Rahman
  • 634
  • 1
  • 5
  • 15