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
 How can I display the values from multiple columns

Author  Topic 

InNomina
Starting Member

40 Posts

Posted - 2011-12-07 : 16:30:50
I have 3 columns with a number in each....

Table - Test
Column A: 123
Column B: 456
Column C: 789

I add a new column D: and I want to see...
Column D: 123456789

Any help is greatly appreciated!

-------------------------
"If you never fail, you're not trying hard enough"

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-12-07 : 17:00:49
Assuming those columns are int or similar:

select convert(varchar(20), columnA) + convert(varchar(20), columnB) + convert(varchar(20), columnC) as columnD
from yourTable

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-12-07 : 17:01:15
If they are varchars or similar:

select columnA + columnB + columnC as columnD
from yourTable

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-12-07 : 17:03:32
[code]ALTER TABLE test
ADD d as (a * 1000000) + (b * 1000) + c[/code]

^^ If they are ints
Go to Top of Page

InNomina
Starting Member

40 Posts

Posted - 2011-12-07 : 18:21:28
I will try it,
Thank you!

-------------------------
"If you never fail, you're not trying hard enough"
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-12-07 : 22:07:16
Mine assumes the values you posted (length of 3 in each column). Tara's would work with any value.
Go to Top of Page
   

- Advertisement -