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
 Query help

Author  Topic 

aswindba1
Yak Posting Veteran

62 Posts

Posted - 2013-04-04 : 16:34:06
Hi Please help for below requirement.

I need to combine two columns of data and insert in new column

I have two columns liek belwo

col1 col2
1 2
1 5
6 1
2 7

I need table like below
Col1 col2 col3
1 2 12
1 5 15
6 1 62
2 7 27

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2013-04-04 : 16:38:47
SELECT Col1, Col2, 10 * Col1 + Col2 AS Col2 FROM dbo.MyTable

SELECT Col1, Col2, CAST(Col1 AS VARCHAR(12)) + CAST(Col2 AS VARCHAR(12)) AS Col3 FROM dbo.MyTable



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

aswindba1
Yak Posting Veteran

62 Posts

Posted - 2013-04-04 : 16:42:21
Hi Thanks for your help..But I need to Insert new column to the table with combined values.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-04-05 : 01:12:25
ALTER TABLE tablename ADD col3 AS col1 * 10 + col2

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -