October 9, 2008 at 9:26 am
Hi,
I have table T1
Col1 Col2
1 09
02 01
01 1
I have to concantenate the columns
Using the below query
SELECT CAST(col1 AS varchar) + CAST( col2 AS varchar) AS ConcatenatedINTs from T1
result set is
ConcatenatedINTs
109
0201
011
But i require result as
19
21
11
i.e to eliminate the '0' from both columns, if it is the first digit of thwe column
Please help
October 9, 2008 at 9:34 am
October 9, 2008 at 9:59 am
why not convert them to ints, then cast then as varchars together?
CREATE TABLE T1(col1 varchar(30),col2 varchar(30) )
insert into T1
SELECT '1','09' UNION
SELECT '02','01' UNION
SELECT '01','1 '
SELECT
convert(varchar,convert(int,col1))
+ convert(varchar,convert(int, col2)) AS ConcatenatedINTs from T1
Lowell
October 9, 2008 at 10:19 am
Yeah... don't do what I posted, that's what I get for trying to respond real quick before I answered someone's email. That way will have you dropping all your zero's.
Lowell's method should work great for you though.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply