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
 merge columns

Author  Topic 

parry02
Starting Member

18 Posts

Posted - 2006-06-20 : 08:12:58
I have 2 columns 'Col1' (char) and 'Col2' (integer)

I'd like to combine these 2 columns and put the result in 'Col3' (char)

please help!!!

nr
SQLTeam MVY

12543 Posts

Posted - 2006-06-20 : 08:42:05
Why would you want to do that?

update tbl set col3 = col1 + convert(varchar(20),col2)


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-20 : 08:50:31
If you use front end application, do the concatenation there

Madhivanan

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

parry02
Starting Member

18 Posts

Posted - 2006-06-20 : 09:19:48
thanks for that but theres a slight problem 'Col3' has leading spaces instead of zeros...
Col1 has 'ABC'
col2 has 1 (default value)
col3 has 'ABC 1'
(without the quotes!

I'm after col3 to contain ABC0000001
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-20 : 09:47:12
What is the purpose of doing this?
Do you want to generate alphanumeric serial no?
If so refer http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=57069

Madhivanan

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

nr
SQLTeam MVY

12543 Posts

Posted - 2006-06-20 : 09:58:00
update tbl set col3 = col1 + right(replicate('0',20) + convert(varchar(20),col2),20)
change the last 20 (or both) to however many digits you want

are you sure col2 is an int - it should have given ABC1
Maybe you need to rtrim col1
update tbl set col3 = rtrim(col1) + right(replicate('0',20) + convert(varchar(20),col2),20)


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -