sqlserver 存储过程使用

创建存储过程


--创建存储过程
create procedure WMSendObj(
    --定义参数
    @org varchar(40),
    @dept varchar(40))
as
begin
    --定义游标
    declare cu cursor for select cno
                          from hr_arc_dispatch_obj
                          where cno in (select cno
                                        from hr_arc_dispatch_obj
                                        where INCLUDEDOWN = 1
                                          and COBJ = @org)
                            and cno not in (select cno
                                            from hr_arc_dispatch_obj
                                            where ctype = '3'
                                              and cobj = @dept)
    --定义变量
    declare @s_cno varchar(40)
    declare @i integer
    --开启游标
    OPEN cu;
    select @i = count(1) + 1 from hr_arc_dispatch_obj;
    --读取游标值
    fetch next from cu into @s_cno
    --循环
    while(@@fetch_status = 0)
        begin
            insert into hr_arc_dispatch_obj
            values (@i, '1', @s_cno, @dept, '3', '1', '0', null, null, null, null, null, null, 1, 1, 1,
                    '2021-12-01 15:14:37',
                    '2021-12-01 15:14:37',
                    1, 2);
            set @i = @i + 1
            fetch next from cu into @s_cno
        end
    --关闭游标
    close cu
    --释放游标
    deallocate cu
END
go

调用存储过程


declare @org  varchar(40) ='123'
declare @dept varchar(40) ='123'
exec WMSendObj @org, @dept

posted @   NewBumblebee  阅读(115)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示