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!

Error in creating Cursor

Status
Not open for further replies.

blackbirdMIT

IS-IT--Management
Aug 28, 2003
22
0
0
US
Table Properties - Odors
OdorID Int
OdorNum Int
Odor nvarchar(50)

Here's my Cursor:
DECLARE OdorCursor Cursor FOR
SELECT * FROM Odors;

DECLARE @TheCursor Cursor;
SET @TheCursor=OdorCursor;

OPEN @TheCursor;

DECLARE @OdorID Int;
DECLARE @OdorNum Int;
DECLARE @Odor nvarchar(50);

FETCH @TheCursor INTO @OdorID, @OdorNum, @Odor;

WHILE @@FETCH_STATUS=0
BEGIN
PRINT @OdorID + @Odor;
FETCH @TheCursor INTO @OdorID, @OdorNum, @Odor;
END

CLOSE @TheCursor;
DEALLOCATE @TheCursor;

--
Here's the syntax error I get:
Server: Msg 245, Level 16, State 1, Line 18
Syntax error converting the nvarchar value 'Warm' to a column of data type int.

How can I resolve the error above?
 
your problem is this line: PRINT @OdorID + @Odor;

@odorid is an int and @odor is a character
So I am guessing you have a number and you are trying to add 'warm' to it

Here is an example of your error...
print 1 + 'warm'
Server: Msg 245, Level 16, State 1, Line 1
Syntax error converting the varchar value 'warm' to a column of data type int.
 
To resolve the problem:

Code:
PRINT CAST(@OdorID AS nvarchar) + @Odor

--James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top