Solved

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

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

14 Experts available now in Live!

Get 1:1 Help Now