如何逐行将存储过程分成表?

时间:2014-01-13 10:22:04

标签: asp.net sql

存储过程包含许多insert,update,delete和truncate语句。我想将所有语句逐个分组到表中。

例如:

create proc Get_Tables as
begin

UPDATE BB_FMCTransactionsTwo SET wsTradeDate = wsSettleDate WHERE wsEntryCode = 'NRT'
UPDATE BB_FMCTransactionsTwo SET wsOK = 1, wsSpecialLogic = SpecialLogic FROM BB_EntryCode INNER JOIN BB_FmcTransactionsTwo ON EntryCode = wsEntryCode
UPDATE BB_FMCTransactionsTwo SET wsFMCFtNt = '' FROM BB_EntryCode INNER JOIN BB_FmcTransactionsTwo ON EntryCode = wsEntryCode   WHERE wsBS <> 'B' AND ( FMCFtNtB IS NULL OR  FMCFtNtB = 'PR' )
UPDATE BB_B204_Tran SET AMOUNT = dbo.BCA_AMT(Desc1, Desc2, Desc3, Udesc1, Udesc2, Udesc3) WHERE TRANIND = 14 AND  PORTTYPE IN (2,3)
DELETE BB_B204_Tran WHERE TRANIND = 14 AND PORTTYPE IN(2,3) AND (Quantity IS NULL  OR ISNUMERIC(Quantity) = 0 OR Quantity = -1 OR ISNUMERIC(AMOUNT) = 0

end

必填:

我想插入更新语句,逐个删除语句......

创建一个存储过程,该存储过程根据语句类型(InsertUpdateTruncate)划分存储过程,并将其逐行插入表中。因此表格如下所示。

表:

Sl.No Statement
1 UPDATE BB_FMCTransactionsTwo SET wsTradeDate = wsSettleDate WHERE wsEntryCode = 'NRT'
2 DELETE BB_B204_Tran WHERE TRANIND = 14 AND PORTTYPE IN(2,3)

1 个答案:

答案 0 :(得分:0)

我已经实现了第一个更新语句,并假设您的AuditTable将有一个SQLData列,因此您需要在商店过程中存储这些SQL语句,如果您使用了任何变量,那么您需要存储到SQL Data变量中并插入审计表。它可能对你有所帮助。

declare @@SQL1 varchar(max)


UPDATE BB_FMCTransactionsTwo SET wsTradeDate = wsSettleDate WHERE wsEntryCode = 'NRT'
set @@SQL1 = 'UPDATE BB_FMCTransactionsTwo SET wsTradeDate = wsSettleDate WHERE wsEntryCode = ''NRT'''
insert into AuditTable (SQLData) values(@@SQL1)

对于变量:

DECLARE @@wsEntryCode VARCHAR(100)
SET @@wsEntryCode='NRT'
PRINT 'UPDATE BB_FMCTransactionsTwo SET wsTradeDate = wsSettleDate WHERE wsEntryCode = ''' + @@wsEntryCode + ''''

insert into AuditTable (SQLData) values(@@SQL1)