Solved

stored procedure to do update

Posted on 2011-09-04
4
212 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
  • 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
In this article I will describe the Backup & Restore 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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now