This is a discussion on Converting a smallint to an nvarchar within the SQL Server forums, part of the Microsoft SQL Server category; --> For a SQL statement in an Alias column I am am combing several columns. But I am having problems ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 nvarchar, without changing the database. |
| |||
| On 29 Sep 2004 23:06:12 -0700, ree32 wrote: >I was wondering is there anyway to format/convert the smallint to >nvarchar, without changing the database. Hi ree32, Use CAST(intcol1 AS varchar(3)). Best, Hugo -- (Remove _NO_ and _SPAM_ to get my e-mail address) |
| |||
| > > Use CAST(intcol1 AS varchar(3)). > > Best, Hugo 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 of the SQL statement |
| ||||
| On 30 Sep 2004 15:31:50 -0700, ree32 wrote: >I found another way of getting around this >convert(char,intcol1 ) 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. >Where would you place your CAST(intcol1 AS varchar(3)) in the context >of the SQL statement It should replace "intcol1". Best, Hugo -- (Remove _NO_ and _SPAM_ to get my e-mail address) |