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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 [Resolved] Get total from rows

Author  Topic 

pyram
Starting Member

12 Posts

Posted - 2012-04-11 : 18:14:28
Hi, I have a table like this:

Create Table Test1
(
Column1 Varchar(20)
,Column2 Varchar(20)
,Column3 Varchar(20)
)

I inserted some data in the table. And i do select query that outputs this result:

John-------1----2
Jessica----3----7

What i would like is an output like this:

John-------1----2---3
Jessica----3----7---10

So it will add the first two numbers and it will display the total at the end.

How can i do this?

thanks...

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-04-11 : 18:20:06
SELECT Column1, Column2, Column3, CAST(Column2 as int) + cast(Column3 as int)
FROM Test1
Go to Top of Page

pyram
Starting Member

12 Posts

Posted - 2012-04-11 : 18:29:22
quote:
Originally posted by robvolk

SELECT Column1, Column2, Column3, CAST(Column2 as int) + cast(Column3 as int)
FROM Test1




thanks a lot!
Go to Top of Page
   

- Advertisement -