• SqlServer 游标生成主外键关联表insert语句


    declare @RR nvarchar(max)
    declare @PCR nvarchar(max)
    declare @RequestRecordId bigint
    declare my_cursor cursor
    for (select a.RequestRecordId from [dbo].[CUP_RequestRecord] a inner join [dbo].[CUP_POSCreditResult] b on b.RequestRecordId=a.RequestRecordId)
    open my_cursor
    fetch next from my_cursor into @RequestRecordId
    while @@fetch_status = 0
        begin
            select @RR='insert into [dbo].[CUP_RequestRecord] select '''+SourceRequest+''',N'''+ApplicationNumber+''',N'''+CONVERT(varchar(100), ApplicationDatetime, 25)+''',N'''+CustomerName+''',N'''+IdentifyType+''',N'''+IdentifyNumber+''',N'''+BankCardNo+''',N'''+MobilePhone+''',N'''+IssueCountry+''',N'''+[Role]+''',N'''+QueryEmployee+''',N'''+QueryReason+''',N'''+ReqDataJson+''',N'''+isnull(ReqSensDataJson,'')+''',N'''+''',N'''+cast(ReqDate as varchar(MAX))+''',N'''+RespCode+''',N'''+RespMsg+''',N'''+''',N'''+''',N'''+case when RespCombiLabelsJson is null then '' else cast(RespCombiLabelsJson as varchar(max)) end+''',N'''+CONVERT(varchar(100), RespDate, 25)+''',N'''+CONVERT(varchar(100), CreateDate, 25)+''',N'''+isnull(EcmStorageStatus,'')+''',N'''+isnull(EcmStorageUrl,'')+'''' from [dbo].[CUP_RequestRecord] where RequestRecordId=@RequestRecordId
            select @PCR='insert into [dbo].[CUP_POSCreditResult] select @@IDENTITY'+','+cast(TotalExpenditureAmt as varchar(MAX))+','+cast(VIPCardNumber as varchar(MAX))+','+cast(HaveHouse as varchar(MAX))+','+cast(HaveCar as varchar(MAX))+','+cast(HaveChild as varchar(MAX))+',N'''+isnull(OneYearExpenditureFirstCity,'')+''',N'''+isnull(OneYearExpenditureSecondCity,'')+''',N'''+isnull(OneYearExpenditureThirdCity,'')+''','+cast(TotallFinancialAmt as varchar(MAX))+','+cast(GinkgoScore as varchar(MAX))+','+cast(AntiFraudScore as varchar(MAX))+','+cast(GoldCardCount as varchar(MAX))+','+cast(TitaniumCardCount as varchar(MAX))+','+cast(PlatinumCardCount as varchar(MAX))+','+cast(DiamondCardCount as varchar(MAX)) from [dbo].[CUP_POSCreditResult] where RequestRecordId=@RequestRecordId
            print @RR
            print @PCR
            set @RR=''
            set @PCR=''
            fetch next from my_cursor into @RequestRecordId
        end
    close my_cursor
    deallocate my_cursor
    go
  • 相关阅读:
    libevent中的bufferevent原理
    libevent中的事件机制
    libevent中数据缓冲区buffer分析
    libevent中最小堆实现算法解析
    我眼中的WebViewJavascriptBridge(图解)
    Tinyhttpd精读解析
    app微信支付的集成步骤
    java工厂模式的测试
    java Annotation 注解的使用
    android 连接蓝牙打印机 BluetoothAdapter
  • 原文地址:https://www.cnblogs.com/hofmann/p/12205033.html
Copyright © 2020-2023  润新知