Solved

stored procedure to do update

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

803 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