Solved

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

Posted on 2014-03-05
2
195 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS SQL 2005 Srink database in chunks 4 58
How to import SQL 2000 database to SQL 2014 5 110
Need help with a query 6 72
CREATE DATABASE ENCRYPTION KEY 1 64
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
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…

776 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