• 使用sqlserver的游标功能来导数据的常见写法


    一定要自己试过才知道么? 你也没试过吃屎,你怎么知道屎不能吃,难道你试过啊...(没有愤怒的意思)

    declare @name nvarchar(100),@email nvarchar(100),@LastLoginIP nvarchar(100)
    declare cursor_data CURSOR
    FOR SELECT  [UserName],[Email],[LastLoginIP] FROM [dbo].[Users] --数据源
    open cursor_data
    fetch from cursor_data into @name,@email,@LastLoginIP --遍历一行值
    while @@fetch_status = 0
     begin
        print @name
        --添加管理员
        INSERT INTO [dbo].[Administrator]
               ([AdministratorName]
               ,[NickName]
               ,[SiteId]
               ,[AdministratorPassword]
               ,[Email]
         VALUES
               (@name
               ,@name
               ,1
               ,'XXXXXXX'
               ,@email)
        --得到管理员ID
        declare @maxid int
        select top 1 @maxid = AdministratorId from [dbo].[Administrator] order by AdministratorId desc
        print convert(nvarchar(100),@maxid)
        --添加管理员角色关联表
        INSERT INTO [dbo].[AdministratorRole]
               ([RoleId]
               ,[AdministratorId])
         VALUES
               (4
               ,@maxid)
        fetch from cursor_data into @name,@email,@LastLoginIP
     end
    close cursor_data
    deallocate cursor_data
    declare @id int
    declare cursor_data CURSOR
    FOR SELECT  ID FROM [dbo].Courses --数据源
    open cursor_data
    fetch from cursor_data into @id --遍历一行值
    while @@fetch_status = 0
     begin
        update Courses set Volumes = (select count(1) from Volumes where CourseID = @id) where ID = @id
        fetch from cursor_data into @id
     end
    close cursor_data
    deallocate cursor_data



  • 相关阅读:
    API之绘图函数
    DotNetCharting
    Rule engine
    股票
    PHP
    获取Excel.dll
    Excel develop
    几个不错的开源的.net界面控件[转贴]
    关于EXCEL文件双击打不开的问题
    Regular expression
  • 原文地址:https://www.cnblogs.com/maijin/p/6097775.html
Copyright © 2020-2023  润新知