如何在C#中编写下面的存储过程
我正在创建类库文件。我遇到了一种情况....不要将脚本文件提供给客户...所以我必须在 C# 代码中创建 SP。我非常想把它保存在 C# 程序集中让我知道这可能吗
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[AdjustTax]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[AdjustTax]
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[AdjustTax]
@IN_SOPType INT,
@IN_SOPNo VARCHAR(21),
@IN_AdjustAmount NUMERIC(19,5),
@O_iError INT OUTPUT
AS
BEGIN
DECLARE @Sequence INT,
@FunctionalAmt NUMERIC(19,5),
@OriginalAmt NUMERIC(19,5),
@TaxDetail VARCHAR(30),
@TaxAmt NUMERIC(19,5),
@CreditAmt NUMERIC(19,5),
@DexRowIDSOP INT,
@SOPHdrTbl VARCHAR(20)
SET NOCOUNT ON;
BEGIN TRANSACTION
SET @O_iError = 0
SELECT @SOPHdrTbl = RTRIM(DB_NAME()) + '.dbo.SOP10100'
SELECT @DexRowIDSOP = DEX_ROW_ID
FROM SOP10100 (nolock)
WHERE SOPTYPE=@IN_SOPType AND SOPNUMBE=@IN_SOPNo
IF (EXISTS(SELECT 1 FROM tempdb..DEX_LOCK (NOLOCK) WHERE table_path_name = @SOPHdrTbl AND row_id = @DexRowIDSOP))
BEGIN
SET @O_iError = 2022
END
ELSE
BEGIN
SET @FunctionalAmt = @IN_AdjustAmount
SET @OriginalAmt = @IN_AdjustAmount
UPDATE SOP10100
SET TAXAMNT = TAXAMNT + @FunctionalAmt,
DOCAMNT = DOCAMNT + @FunctionalAmt,
ACCTAMNT = ACCTAMNT + @FunctionalAmt,
ORTAXAMT = ORTAXAMT + @OriginalAmt,
ORDOCAMT = ORDOCAMT + @OriginalAmt,
ORACTAMT = ORACTAMT + @OriginalAmt
WHERE SOPTYPE=@IN_SOPType AND SOPNUMBE=@IN_SOPNo
SELECT TOP 1 @TaxDetail = TAXDTLID, @TaxAmt = STAXAMNT
FROM SOP10105
WHERE SOPTYPE=@IN_SOPType AND SOPNUMBE=@IN_SOPNo
ORDER BY LNITMSEQ
UPDATE SOP10105
SET STAXAMNT = STAXAMNT + @FunctionalAmt,
ORSLSTAX = ORSLSTAX + @OriginalAmt -- Currently the same as Functional Amount
WHERE SOPTYPE=@IN_SOPType AND SOPNUMBE=@IN_SOPNo
AND LNITMSEQ=0
AND TAXDTLID=@TaxDetail
SELECT TOP 1 @Sequence = SEQNUMBR, @CreditAmt=CRDTAMNT
FROM SOP10102
WHERE SOPTYPE=@IN_SOPType AND SOPNUMBE=@IN_SOPNo
AND DISTTYPE=9
AND ((DEBITAMT + CRDTAMNT) = @TaxAmt)
IF (@CreditAmt <> 0)
BEGIN
UPDATE SOP10102
SET CRDTAMNT = CRDTAMNT + @FunctionalAmt,
ORCRDAMT = ORCRDAMT + @OriginalAmt
WHERE SOPTYPE=@IN_SOPType AND SOPNUMBE=@IN_SOPNo
AND SEQNUMBR=@Sequence
END
ELSE
BEGIN
UPDATE SOP10102
SET DEBITAMT = DEBITAMT + @FunctionalAmt,
ORDBTAMT = ORDBTAMT + @OriginalAmt
WHERE SOPTYPE=@IN_SOPType AND SOPNUMBE=@IN_SOPNo
AND SEQNUMBR=@Sequence
END
SELECT TOP 1 @Sequence = SEQNUMBR, @CreditAmt=CRDTAMNT
FROM SOP10102
WHERE SOPTYPE=@IN_SOPType AND SOPNUMBE=@IN_SOPNo
AND DISTTYPE=2 AND ((DEBITAMT + CRDTAMNT) > 0.0)
IF (@CreditAmt <> 0)
BEGIN
UPDATE SOP10102
SET CRDTAMNT = CRDTAMNT + @FunctionalAmt,
ORCRDAMT = ORCRDAMT + @OriginalAmt
WHERE SOPTYPE=@IN_SOPType AND SOPNUMBE=@IN_SOPNo
AND SEQNUMBR=@Sequence
END
ELSE
BEGIN
UPDATE SOP10102
SET DEBITAMT = DEBITAMT + @FunctionalAmt,
ORDBTAMT = ORDBTAMT + @OriginalAmt
WHERE SOPTYPE=@IN_SOPType AND SOPNUMBE=@IN_SOPNo
AND SEQNUMBR=@Sequence
END
END
IF (@O_iError = 0)
COMMIT TRANSACTION
ELSE
ROLLBACK TRANSACTION
END
GO