I have a table in SQL Server 2005 filled with data. Is there a method by which I can generate update statements including the data in it?
A:
If you don't find any better solution, try this:
SELECT
'UPDATE [Table] (field1, field2, field3) Values ('
+ field1 + ', '
+ field2 + ', '
+ field3 + ')'
FROM [Table]
I know, not nice.
Stefan Steinegger
2010-07-06 11:42:26
A:
Go here and get the Microsoft SQL Server Management Studio Express SSMSE Download page
After installing you can then connect to your database with the tool and generate several types of "vanilla" scripts.
Michael Bazos
2010-07-06 11:43:44
A:
If you mean data on the same row, just use it in the Update Statement
Update MyTable Set ColumnA = ColumnB + ColumnC
If you want to use data from other rows, you probably have to join it back to it's self
Update a
Set ColumnA = b.ColumnD
From MyTable a
Join MyTable b on a.ColumnB = b.ColumnC
DaveShaw
2010-07-06 11:46:37
A:
SELECT
'UPDATE [Table] SET field1 = ' + field1 + ' , field2 = ' + field2 + ' , field3 = ' + field3 + ' WHERE <condition> ' FROM <Table>
Use extra single Quotes wherever string data is updated.
Baaju
2010-07-06 11:46:52
A:
There's a nice free tool here http://www.lss.co.uk/Products/LiveDataScript/
SPE109
2010-07-06 16:52:01