# How do I compute for the total of the value in Alias vladd1, vladd2, vladd3, vladd...

 0 Hi, How do I compute for the total of the value in Alias vladd1, vladd2, vladd3, vladd4 or any alternative using declare statement ? Here is my sample statement below. ``` select alan8, case when rtrim(aladd1) '' then len(aladd1) + 9 else 0 end as vladd1 , case when rtrim(aladd1) '' then len(aladd2) + 9 else 0 end as vladd2 , case when rtrim(aladd1) '' then len(aladd3) + 9 else 0 end as vladd3 , case when rtrim(aladd1) '' then len(aladd4) + 9 else 0 end as vladd4, vladd1 + vladd2 + vladd3 + vladd4 as Total from Customers ``` Thanks and appreciate your help. Regards,cyberarent2 more ▼ asked Nov 23, 2009 at 04:04 AM in Default cyberarnet2 1 ● 1 ● 1 ● 1 Kristen ♦ 2.2k ● 6 ● 7 ● 10 add new comment (comments are locked) 10|1200 characters needed characters left ▼ Viewable by all users

1 answer: sort voted first
 0 Something similar to this?``select alan8, sum(case when aladd1 > '' then len(aladd1) + 9 else 0 end) as vladd1, sum(case when aladd2 > '' then len(aladd2) + 9 else 0 end) as vladd2, sum(case when aladd3 > '' then len(aladd3) + 9 else 0 end) as vladd3, sum(case when aladd4 > '' then len(aladd4) + 9 else 0 end) as vladd4, SUM(len(aladd1) + len(aladd2) + len(aladd3) + len(aladd4) + 36) as Totalfrom Customersgroup by alan8`` more ▼ answered Nov 23, 2009 at 04:51 AM Peso 1.6k ● 5 ● 6 ● 8 add new comment (comments are locked) 10|1200 characters needed characters left ▼ Viewable by all users

### New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x476
x60

asked: Nov 23, 2009 at 04:04 AM

Seen: 743 times

Last Updated: Nov 23, 2009 at 05:54 AM