Solved

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

Posted on 2014-03-05
2
202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

628 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