Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 combine value of three columns

Author  Topic 

eugz
Posting Yak Master

210 Posts

Posted - 2013-04-04 : 20:37:16
I have four fields Status, PaidAmount, AdjustAmount, WriteOff. Based on this data I populate ListView. The result looks like:
----------------------------------------------------
Status..........PaidAmount......AdjustAmount......WriteOff
Paid................$1500
Adjustment................................$150
WriteOff.......................................................130
----------------------------------------------------

I would like combine PaidAmount and AdjustmentAmount in new column, for instance, Amount to get result like:
----------------------------------------------------
Status.........Amount
Paid..............$1500
Adjustment......$150
WriteOff..........$130
----------------------------------------------------
If is it possible how it to do?

Thanks.

chadmat
The Chadinator

1974 Posts

Posted - 2013-04-04 : 21:14:41
create table #t1 (status varchar(10), PaidAmount money, AdjustmentAmount money, Writeoff money)

insert into #t1 VALUES ('Paid', 1500, null, null)
insert into #t1 VALUES ('Adjustment', null, 150, null)
insert into #t1 VALUES ('WriteOff', null, null, 130)
GO

SELECT status, COALESCE(PaidAmount, AdjustmentAmount, WriteOff) Amount
FROM #t1

GO

DROP Table #t1



-Chad
Go to Top of Page
   

- Advertisement -