Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query help
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Yak Posting Veteran

62 Posts

Posted - 04/04/2013 :  16:34:06  Show Profile  Reply with Quote
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

Patron Saint of Lost Yaks

30421 Posts

Posted - 04/04/2013 :  16:38:47  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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

Yak Posting Veteran

62 Posts

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

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 04/05/2013 :  01:12:25  Show Profile  Reply with Quote
ALTER TABLE tablename ADD col3 AS col1 * 10 + col2

SQL Server MVP
Go to Top of Page
  Previous Topic Topic Next 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.04 seconds. Powered By: Snitz Forums 2000