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 |
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 |
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.