Groups | Blog | Home
all groups > sql server (alternate) > september 2004 >

sql server (alternate) : Converting a smallint to an nvarchar



ree32 NO[at]SPAM hotmail.com
9/29/2004 11:06:12 PM
For a SQL statement in an Alias column I am am combing several
columns.
But I am having problems with one column as it is a smallint.

I get this error
Syntax error converting the nvarchar value to a column of data type
smallint


My Sql statement "
Select Stilngcol1 + stringcol2 + intcol1 + stringcol3 As NewColName
from Table1

I was wondering is there anyway to format/convert the smallint to
Hugo Kornelis
9/30/2004 10:25:30 AM
[quoted text, click to view]

Hi ree32,

Use CAST(intcol1 AS varchar(3)).

Best, Hugo
--

ree32 NO[at]SPAM hotmail.com
9/30/2004 3:31:50 PM
[quoted text, click to view]

Thanks

I found another way of getting around this
convert(char,intcol1 )

Where would you place your CAST(intcol1 AS varchar(3)) in the context
Hugo Kornelis
10/1/2004 10:48:10 AM
[quoted text, click to view]

Hi ree32,

CONVERT and CAST are pretty much equivalent. Except that CONVERT allows
for more control when you're converting date and time data or fractions
and CAST is ANSI standard (ie more portable to other databases).

I use CAST, except when I need the added control CONVERT gives me.


[quoted text, click to view]

It should replace "intcol1".

Best, Hugo
--

AddThis Social Bookmark Button