Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax error converting nvarchar value to a column of data type int

Status
Not open for further replies.

BDW1969

IS-IT--Management
Aug 29, 2002
43
0
0
US
Any help would be appreciated. Below is my SQL statement and this is the error that I keep getting. I have checked the DB and the FirstName is nvarchar and ID is an Int. This statement is coming from and ASP.NET page

"SELECT FirstName, ID, FirstName + ' ' + ID AS FirstID FROM TblPolicy ORDER BY FirstName
 
SELECT FirstName, ID, FirstName + ' ' + Convert(VarChar(20),ID) AS FirstID FROM TblPolicy ORDER BY FirstName
 
Tahnks for the reply, the problem I think is with the firstname. I tried your code and received the following.

The last SQL statement

SELECT FirstName, ID, convert(nvarchar(100),FirstName) + ' ' + ID AS FirstID FROM TblPolicy ORDER BY FirstName

Syntax error converting the nvarchar value 'XXX' to a column of data type int
 
FirstName is already an nVarChar. You need to convert the ID Field to nVarChar.

Also, take a closer look at the data types. nVarChar is for unicode strings. VarChar is for "normal" string. nVarChars take twice the storage room as a VarChar.
 
WOW thanks so much, you were right and it works great!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top