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.
| Author |
Topic |
|
Vignesh
Starting Member
20 Posts |
Posted - 2006-05-09 : 11:17:56
|
| hello alli am trying to concatenate strings in SQL Server by using '+' operator. but the problem is i have a code like this 1201 and another code like 0003 and when i use + operator. it removes the leading zeroes. i dont want to remove the leading zeros. how do i do thisThanks in advanceVignesh |
|
|
mfemenel
Professor Frink
1421 Posts |
Posted - 2006-05-09 : 12:15:56
|
| cast your columns as varchar, then concatenate them. If you have a column that's storing these values it would look like this: cast(columnA as varchar(20)) + cast(columnb as varchar(20)). This will treat your columns as character data and allow the concatenation without dropping the leading 0's.Mike"oh, that monkey is going to pay" |
 |
|
|
Vignesh
Starting Member
20 Posts |
Posted - 2006-05-09 : 13:30:34
|
| hi Mikethe columns are defined as varchar only. Vignesh |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-05-09 : 13:39:12
|
| It works fine for me:DECLARE @a varchar(4), @b varchar(4)SELECT @a = '1201', @b = '0003'SELECT @a + @bSELECT @b + @aTara Kizeraka tduggan |
 |
|
|
Vignesh
Starting Member
20 Posts |
Posted - 2006-05-09 : 15:13:43
|
| Hi Tarathe code works fine for me alsobut if i have to concatenate two columns how do i do that.Vignesh |
 |
|
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2006-05-09 : 15:29:17
|
Vignesh, I'm not telling anything different from the others. I'm just answering to ur specific question. (Means, the answers given by the others are more than enough for u ) Create table #t (a varchar(10), b varchar(10))Insert into #t SELECT '1201', '0003'Select a, b, a + b from #tDrop table #t Srinika |
 |
|
|
Vignesh
Starting Member
20 Posts |
Posted - 2006-05-09 : 15:39:14
|
| thank you allits working. sorry did a silly mistake. thanks all for your replies.VigneshVignesh |
 |
|
|
|
|
|