Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

stored procedure to do update

Posted on 2011-09-04
4
Medium Priority
?
222 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 2000 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] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

971 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