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 to add int and string values

Author  Topic 

rudba
Constraint Violating Yak Guru

415 Posts

Posted - 2009-08-24 : 11:57:51
How do i update Col3 fields with Col1 value + Col2 value
Col1 is INT field, Col2 is string field.

Declare @tbl1 table
(ID INT,
Col1 INT,
Col2 varchar(10),
Col3 varchar(15)
)

INSERT INTO @tbl1
SELECT 1, 0,'Abc',NULL

INSERT INTO @tbl1
SELECT 2,1,'xyz',NULL

INSERT INTO @tbl1
SELECT 3,1,'Mnop',NULL

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-08-24 : 12:00:15
you mean this??

update @tbl1
set Col3 = convert(varchar(10),Col1) + Col2
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-08-25 : 03:04:37
Why dont you use this?

select col1,col2,convert(varchar(10),Col1) + Col2 as col3 from @tbl1

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -