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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 CONCATENATION

Author  Topic 

wotrac
Yak Posting Veteran

98 Posts

Posted - 2002-07-27 : 16:25:19
I have 3 fields in my SQL table.
Field 1 is a VARCHAR(10)
Field 2 is a VARCHAR(6)
Field 3 is a VARCHAR(16)

I need to Concatenate fields 1 & 2 and Insert them into field 3 .
But if the length of field 1 is less than 10 characters, I need to add spaces to the end of the string before adding field 2

NB Field 1 can have variable field lengths from 4 to 10.

If it was fixed I would be OK

Can Anyone help.



jasper_smith
SQL Server MVP & SQLTeam MVY

846 Posts

Posted - 2002-07-27 : 16:48:16
Assumes no nulls and field1 has a min length of 4
Gives you the idea anyway

update mytable
set field3 = ( LEFT( field1 + ' ', 10 ) + field2 )




HTH
Jasper Smith


Edited by - jasper_smith on 07/27/2002 16:52:38
Go to Top of Page

ojn.
Starting Member

10 Posts

Posted - 2002-07-29 : 17:41:13
update tb
set field3 = convert(char(10),field1)+field2

--
-oj
www.rac4sql.net
Go to Top of Page
   

- Advertisement -