Link to home
Start Free TrialLog in
Avatar of hillelben
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
Avatar of oleggold
oleggold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hillelben
hillelben

ASKER

in mysql you could do something like this inside a stored procedure...
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
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)