惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The Cloudflare Blog
U
Unit 42
D
Docker
Hugging Face - Blog
Hugging Face - Blog
博客园 - 聂微东
Recent Announcements
Recent Announcements
GbyAI
GbyAI
T
The Blog of Author Tim Ferriss
Last Week in AI
Last Week in AI
V
Visual Studio Blog
I
InfoQ
Google DeepMind News
Google DeepMind News
小众软件
小众软件
L
LangChain Blog
C
Check Point Blog
宝玉的分享
宝玉的分享
Martin Fowler
Martin Fowler
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 【当耐特】
J
Java Code Geeks
罗磊的独立博客

博客园 - 蕭慶蘋

pymssql调用sqlserver存储过程带output 参数 数据库锁 oracle instr,substr 截取字符串 循环读取写入表 Oracle For 循环,字符串拼接,查找 Putty PSCP iis,webservice 启用 acrobat.exe 打印 iis,webservice 打印 Oracle查询包,同义词 Oracle 截取字符串,取系统时间 Sqlserver连接Oracle数据库 Java 连oracle 12C 起步_PreparedStatement Java 连oracle 12C 起步 powershell excel 导入 sqlserver 更改存储过程的所有者 jquery-autocomplete 参数说明 了解SQL Server触发器及触发器中的事务 经典SQL语句大全 事务使用
sqlserver 游标
蕭慶蘋 · 2016-03-14 · via 博客园 - 蕭慶蘋

游标使用

--新建ERP临时表
if object_id('tempdb..#ERP_interface') is not null 
     drop table #ERP_interface
    
--将ERP中间表,写入条码系统临时表
select * into #ERP_interface  from 
openquery(SYN_ERP, 'select * from FYG.FYG_INV_TRANS_INT_TEMP st ')
WHERE TS>'2016-01-01'

--select * from #ERP_interface

--新建条码临时表
if object_id('tempdb..#BarCode_interface') is not null 
     drop table #BarCode_interface

--将oracleinterface状态为1的数据,写入条码系统临时表

select * into #BarCode_interface from [WMS_BarCode_V10_SH].[dbo].[OracleInterface] 
where status<>2 and operatetime>'2016-01-01' and status=1

--select * from #BarCode_interface

DECLARE @BarcodeId varchar(255)
DECLARE @TranceNo varchar(255)

DECLARE My_Cursor CURSOR                             --定义游标
FOR (SELECT id FROM #BarCode_interface)                 --查出需要的集合放到游标中
OPEN My_Cursor;                                      --打开游标
FETCH NEXT FROM My_Cursor INTO @BarcodeId;           --读取第一行数据
WHILE @@FETCH_STATUS = 0
    BEGIN

    UPDATE [WMS_BarCode_V10_SH].[dbo].[LabelTransactionInfo]
       SET [Status] = 1
     WHERE transactionid=@BarcodeId

        select @TranceNo=TraceNo from #BarCode_interface where id=@BarcodeId;
        
    UPDATE [WMS_BarCode_V10_SH].[dbo].[BizTransactionInfo]
       SET [Status] = 2      
     WHERE [WMS_BarCode_V10_SH].[dbo].[BizTransactionInfo].Traceno=@TranceNo
        
    if exists (select * from #ERP_interface where codebar_id=@BarcodeId and transaction_reference=@TranceNo)
            begin
                DECLARE @ERRORMESSGAE varchar(255)
                DECLARE @STATUS NVARCHAR(255)
                select @STATUS=[STATUS],@ERRORMESSGAE=ERROR_EXPLANATION from #ERP_interface where codebar_id=@BarcodeId and transaction_reference=@TranceNo
                IF(@STATUS IS NULL OR @STATUS='I')
                    PRINT 'IS DOING'
                ELSE
                    UPDATE [WMS_BarCode_V10_SH].[dbo].[OracleInterface] SET STATUS=-1,errormessage=@ERRORMESSGAE WHERE ID=@BarcodeId;
            end
        else
            BEGIN
                UPDATE [WMS_BarCode_V10_SH].[dbo].[OracleInterface] SET STATUS=2 WHERE ID=@BarcodeId;
            END       
            
        FETCH NEXT FROM My_Cursor INTO @BarcodeId;
    END
CLOSE My_Cursor;                                     --关闭游标
DEALLOCATE My_Cursor;                                 --释放游标

posted @ 2016-03-14 21:55  蕭慶蘋  阅读(316)  评论()    收藏  举报