Solved

How to update the table with information of the update command written in table

Posted on 2014-03-05
2
190 Views
Last Modified: 2014-04-14
example
Table name mstupdates, which contains the fields table, field,old,new
table      field      old      new
mstchvs      aa      1      19
transbcc1       bb      32      343

table refers to table to be updated
field refers to column name
old refers to old value
new refers to new value
of the table.

How to use update command.

update table set field=nv where ov=ov
0
Comment
Question by:searchsanjaysharma
2 Comments
 
LVL 11

Accepted Solution

by:
John_Vidmar earned 500 total points
ID: 39906231
Dynamic-SQL:
declare	@ls_SQL		varchar(1000)
,	@ls_table	varchar(100)
,	@ls_field	varchar(100)
,	@li_old		int
,	@li_new		int

declare lcur_whatever cursor for
	select	[table]
	,	[field]
	,	[old]
	,	[new]
	from	mstupdates

open lcur_whatever

while (1=1) begin
	fetch next from lcur_whatever into @ls_table, @ls_field, @li_old, @li_new
	if @@fetch_status <> 0 break

	SET @ls_SQL = 'update '+ @ls_table +' set '+ @ls_field +' = '+ Str(@li_new) +' where '+ @ls_field +' = '+ Str(@li_old)
	print @ls_SQL

	exec (@ls_SQL)
	if @@error <> 0 break
end

close lcur_whatever
deallocate lcur_whatever

Open in new window

0
 

Author Closing Comment

by:searchsanjaysharma
ID: 39999684
tx
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why does this keep coming up NULL? 2 43
PERFORMANCE OF SQL QUERY 13 66
Isolation level in SQL server 3 47
Truncate vs Delete 63 101
This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

910 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

17 Experts available now in Live!

Get 1:1 Help Now