procedure basic Points
1-i have a table with primary key of type int
2-i have acolumn in this table of type uniqueidentifier its name is the same name of primarykey + the word spare
3-i use this spare column to put a uniqueidentifier depending on primary key value
the stored procedure is
Create Procedure Update_Values
@tablename as nvarchar(255),
@PrimaryKey as nvarchar(255),
@IDValue as uniqueidentifier
as
Declare @Declarestatement as nvarchar(1000)
Declare @SelectStatement as nvarchar(1000)
Declare @UpdateStatement as nvarchar(1000)
Declare @ID as int
Declare @A as Cursor
Set @SelectStatement = 'Select ' + @PrimaryKey + ' From ' + @tablename
Set @Declarestatement = 'Set @cursor = cursor forward_only static for ' + @SelectStatement + ' open @cursor;'
Exec(@DeclareStatement)
Exec (@DeclareStatement)
while (@@fetch_status = 0)
begin
Fetch Next From A Into @ID
Set @UpdateStatement = 'Update ' + @tablename + ' Set ' + @PrimaryKey + '_Spare' + '=' + @IDvalue+ 'Where ' + @PrimaryKey + '=' + @ID
Exec(@UpdateStatement)
end
Close A
Deallocate A
but i got the following error
Msg 402, Level 16, State 1, Procedure Update_Values, Line 18
The data types nvarchar and uniqueidentifier are incompatible in the add operator.
the line which i get the error in is
Set @UpdateStatement = 'Update ' + @tablename + ' Set ' + @PrimaryKey + '_Spare' + '=' + @IDvalue+ 'Where ' + @PrimaryKey + '=' + @ID89
the problem is @primarykey is aprimary key name
can you help me