hillelben
asked on
stored procedure to do update
how would you make a stored procedure that takes as a parameter a list of fields and their values to update and another parameter with where arguments and do an update for a certain table with this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
never mind looks like the 3rd link you gave shows how to do this
hi hillelben:
you can do the following
Declare @QRY varchar(1000)
set @QRY = 'Update Table set col1 = ' + 5 + ' where name = ''jack''; '
Exec (@QRY)
you can do the following
Declare @QRY varchar(1000)
set @QRY = 'Update Table set col1 = ' + 5 + ' where name = ''jack''; '
Exec (@QRY)
ASKER
SET @stmnt= CONCAT(UPDATE mytable SET ‘,@update_agrs,' WHERE', @where_args);
PREPARE stmnt FROM @stmnt;
EXECUTE stmnt;
can you do something like this in sql server where you can construct a query with arguments for column names, and update values. the thing i haven't found is how to get text in a parameter to be used as column names in a query.
thanks