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

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Dynamic update

Author  Topic 

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2010-12-16 : 12:46:17
I need a dynamic script which should generate update scripts from the table.

Ex:



Table
-----

ID user Email
--- ---- ----------
10 sam sam@g.com
20 pat pat@p.com
30 Rob Rob@r.com
40 Jack Jack@j.com

Update table set ID = 10,user = 'sam', cdate = getdate() Where Email = 'sam@g.com'
Update pat@p.com set ID = 20,user = 'pat', cdate = getdate() Where Email = 'pat@p.com'
Update pat@p.com set ID = 30,user = 'Rob', cdate = getdate() Where Email = 'Rob@g.com'
Update pat@p.com set ID = 40,user = 'Jack', cdate = getdate() Where Email = 'Jack@g.com'



Thanks for you help in advance

X002548
Not Just a Number

15586 Posts

Posted - 2010-12-16 : 13:01:21
SELECT 'UPDATE Table SET ID = ' + [ID] + ', '
+ 'USER = ' + '''' + [USER] + '''' + ', '
+ 'CDATE = GETDATE() '
+ 'WHERE EMAIL = ' + '''' + Email + ''''



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2010-12-16 : 20:18:17
Thanks Brett
Go to Top of Page
   

- Advertisement -