是否有任何工具可以使用EscapeConcatenation将存储过程SQL转换为字符串?

时间:2019-01-14 16:44:18

标签: sql-server tsql ssms

我有50多个存储过程需要转换,以便可以在其中使用动态的子句。我的选择状态记忆在SQL中看起来像这样。我需要将其更改为varchar(max)字符串,并使用Execute(@SQL)或sp_executesql @SQL

有没有在线或购买的工具可以将此where子句转换为具有正确的@Parameters转义序列的字符串格式?

;WITH TempResult AS(SELECT  
        DataDt
        ,EffDt
        ,SettlementDt
        ,BankId
        ,SeqNum
        ,DeleteFlag
        ,LoanNum
        ,BondLoanSaleType
        ,PurchaseProceedsAmt
        ,SettledPrinBal
        ,IntRecMiscAmt
        ,BuydownCashClearingAmt
        ,ARClearingDAPAmt
        ,ARCashClearingAmt
        ,ARSuspenseAmt
        ,ImpoundsSoldLoansAmt
        ,BondCommitmentFeesAmt
        ,SRPAmt
        ,OtherFeeAmt
        ,ActiveFlagBit = case ActiveFlagBit when 1 then 1 else 0 end
        ,UploadByCfcUserId
        ,UploadDtTm
        ,UploadedFileName
        ,ApprovedFlagBit   = case ApprovedFlagBit when 1 then 1 else 0 end
        ,ApproveRejectByCfcUserId
        ,ApproveRejectDtTm
        ,ApprovalTaskId
        ,ArchiveDtTm
  FROM guiUploadBondLoanSales u (nolock)
    WHERE  
        (@LoanList.exist('/NewDataSet/Table1') = 0 or LoanNum in (select LoanNum from #tmpLoan))
        and (@DataDtTo = '01/01/1900' or DataDt between @DataDtFrom and @DataDtTo)
        and (@SettlementDtTo = '01/01/1900' or SettlementDt between @SettlementDtFrom and @SettlementDtTo)
        and (@ShowOnlyLatest = 0 or (ActiveFlagBit = 1 and ApprovedFlagBit = 1 and u.DataDt = 
            (select max(DataDt) from guiUploadBondLoanSales u1 (nolock)
                where u1.LoanNum = u.LoanNum and u1.ActiveFlagBit = 1 and u1.ApprovedFlagBit = 1)))
        and (@TaskId = 0 or ApprovalTaskId = @TaskId)
        and (@FileName = '' or UploadedFileName like '%' + @FileName + '%')
        and (@UploadedByUsers.exist('/NewDataSet/Table1') = 0 or UploadByCfcUserId in (select UploadedByUsers from #UploadedByUsers))
        and (@ApprovedByUsers.exist('/NewDataSet/Table1') = 0 or ApproveRejectByCfcUserId in (select ApprovedByUsers from #ApprovedByUsers))
        and (@UploadDtTo = '01/01/1900' or UploadDtTm between @UploadDtFrom and @UploadDtTo)
        and (@ApprovedDtTo = '01/01/1900' or ApproveRejectDtTm between @ApprovedDtFrom and @ApprovedDtTo)
        and (@HideArchive = 0 or u.ArchiveDtTm = '1/1/1900' )
    ), TempCount AS (  SELECT COUNT(*) AS MaxRows FROM TempResult) SELECT *, TempCount.MaxRows FROM TempResult, TempCount ORDER BY TempResult.UploadDtTm    OFFSET @OFFSET ROWS FETCH NEXT @FETCH ROWS ONLY OPTION(RECOMPILE)

0 个答案:

没有答案