Solved

stored procedure to do update

Posted on 2011-09-04
4
217 Views
Last Modified: 2012-05-12
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?
0
Comment
Question by:hillelben
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 21

Accepted Solution

by:
oleggold earned 500 total points
ID: 36482371
0
 

Author Comment

by:hillelben
ID: 36482456
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
0
 

Author Comment

by:hillelben
ID: 36482469
never mind looks like the 3rd link you gave shows how to do this
0
 
LVL 15

Expert Comment

by:AmmarR
ID: 36482488
hi hillelben:

you can do the following

Declare @QRY varchar(1000)

set @QRY = 'Update Table set col1 = ' +  5 + ' where name = ''jack''; '

Exec (@QRY)
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question