Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Update multiple tables
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Aged Yak Warrior

530 Posts

Posted - 11/04/2013 :  13:25:31  Show Profile  Reply with Quote
I have a table that holds a list of fields in it.
TableName = FieldList
In my table FieldList I have one field called Field1 which holds each table.field


I want to change the value in all of those fields in each table. Can a script be written to read this list and update the item_no field all at once?

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 11/04/2013 :  13:34:32  Show Profile  Reply with Quote
Run a query such as this to generate the update statements, copy those update statements to an SSMS query window and run it.
SELECT 'Update ' + LEFT(field1,CHARINDEX('.',field1)-1) + ' set ' + STUFF(field1,1,CHARINDEX('.',field1),'')
	+ ' = YourNewValueHere'
FROM FieldList;
Please do review the generated SQL statements to make sure that it is correct and that that is what you want to do.

You could also make those statements into a dynamic SQL string and then use EXEC or sp_executesql to execute that dynamic string.
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000