Concatination

In SQL Server 2005 how can i concatinate a string with an Integer??

for example I have a table named Branch_Details in which there is a field named B_Code which is numeric, and when I use SELECT query I want it to be displayed in B001, B002, B003.........B00n format. How can i accompalish this??
[305 byte] By [maverick786us] at [2007-11-20 9:10:53]
# 1 Re: Concatination
You mean you want to take 1000 rows of one int column ,and turn them into 1 row of 1 column where the value is the string concat of all rows?

1
2
3
...
998
999
1000

->

"1, 2, 3, ..., 998, 999, 1000"

-
It's hard. I'd just do it in the client side code
cjard at 2007-11-9 13:45:18 >
# 2 Re: Concatination
Either that or you mean:

SELECT 'B' + 123
cjard at 2007-11-9 13:46:19 >
# 3 Re: Concatination
Either that or you mean:

SELECT 'B' + 123

I have tried that in my SQL Server 2005 but it generates error. That it cannot convert integer into string
maverick786us at 2007-11-9 13:47:29 >
# 4 Re: Concatination
erm.. more like that its trying to convert the 'B' into an int..

Try

select 'B' + CAST(123 AS VARCHAR)

Or use oracle. Its much less dumb with things like this.
cjard at 2007-11-9 13:48:23 >
# 5 Re: Concatination
erm.. more like that its trying to convert the 'B' into an int..

Try

select 'B' + CAST(123 AS VARCHAR)

Or use oracle. Its much less dumb with things like this.

Thanks it worked. In front of Oracle 9i. I consider SQL Server 2005 dull
maverick786us at 2007-11-9 13:49:22 >
# 6 Re: Concatination
That makes two of us :)
cjard at 2007-11-9 13:50:22 >
# 7 Re: Concatination
OK now I want a slight change. My Query is like this.

SELECT 'B00' + CAST(B_Code AS VARCHAR) FROM Paramet

Where B_Code is a numeric

Now there is a slight problem. If the value of B_Code is in single digit then its OK but if its 2 digits lets say 17, then it will Display B0017 similarly if its 3 digits lets say 100, it will display B00100.

But I don't want it this way. I want it to be displayed in such a way that in first case it should display B017 and in 2nd case B100. How can I achieve this??

Thanks in Advance
maverick786us at 2007-11-9 13:51:26 >