SQL Server Cursors

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.