zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    初识echarts
    深浅拷贝的理解
    react基本语法及组件
    webpack使用
    网上面试资料整理
    封装原生promise函数
    vue路由懒加载及组件懒加载
    译文---C#堆VS栈(Part Four)
    译文---C#堆VS栈(Part Three)
    译文---C#堆VS栈(Part Two)
  • 原文地址:https://www.cnblogs.com/hofmann/p/12205033.html
Copyright © 2011-2022 走看看