DECLARE Changeinvcodecursor CURSOR
For SELECT A.name as tablecolumn,c.name as TableName from Sys.columns A left joins sys.types B on a.user_type_id = b.user_t ype_id right JOIN sys.tables C in c.object_id=a.object_id WHERE a.name = ' cinvcode ' OR a.name= ' Invcode ' ORDER by c.name
--Open cursor
OPEN Changeinvcodecursor
DECLARE @tablecolumn1 nvarchar (120)
DECLARE @tablename1 nvarchar (120)
DECLARE @strsql nvarchar (2048)
DECLARE @BeforeCode nvarchar (120)
DECLARE @afterCode nvarchar (120)
FETCH NEXT from Changeinvcodecursor to @tablecolumn1, @tablename1
While @ @FETCH_STATUS =0
BEGIN
--Pre-change inventory code
Set @BeforeCode = ' 0111 '
--post-Change inventory code
Set @afterCode = ' 0222 '
Set @strsql = ' Update ' [email protected]+ ' Set ' [email protected]+ ' = ' [email protected]+ ' WHERE ' [email protected]+ ' = ' ' [email protected]+ ']
EXEC (@strsql)
FETCH NEXT from Changeinvcodecursor to @tablecolumn1, @tablename1
END
--Close cursor
CLOSE Changeinvcodecursor
Deallocate changeinvcodecursor
SQL Server Cursors