SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 combine value of three columns
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

eugz
Posting Yak Master

195 Posts

Posted - 04/04/2013 :  20:37:16  Show Profile  Reply with Quote
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.

Edited by - eugz on 04/04/2013 20:59:58

chadmat
The Chadinator

USA
1974 Posts

Posted - 04/04/2013 :  21:14:41  Show Profile  Visit chadmat's Homepage  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000