Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9001837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:29:23+00:00 2026-06-16T00:29:23+00:00

how to write below stored procedure in C# i am creating class library file.

  • 0

how to write below stored procedure in C#

i am creating class library file. i get a situation….not to give the scirpt file to clients…so i have to create SP in c# code. I desperately want to keep it in C# assembly
Let me know is this possible

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:29:23+00:00Added an answer on June 16, 2026 at 12:29 am

    Why would you write it in C# in the first place?

    If you want to manage DB schema use Visual Studio Database project.

    If you desperately want to keep it in C# assembly, create a separate .sql file, embed it as a resource and load it in C# as a string.

    In file properties change Build Action to Embedded Resource and use the following code to load it

    using (Stream stream = Assembly.GetExecutingAssembly()
                                   .GetManifestResourceStream("Your assembly namespace" + "file.sql"))
    using (StreamReader reader = new StreamReader(stream))
    {
        string result = reader.ReadToEnd();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to write a calculation for the below scenario in the stored procedure
Below is pseudo-code for SQL Server stored procedure I need to write: int[] followers
I want to write a stored procedure that queries XML files after I have
i write below code for sending id to another php file function selectCheckBox(k) {
I don't have access to my dev environment, but when I write the below:
I write the code below to delete a file: FileInfo file = new FileInfo(filename);
I write a controller like below: public class AccountController : Controller { public ActionResult
I'm really having a hard time to write the stored procedure. Here is the
I am new to SQL and trying to write a stored procedure. I am
I'm first time trying to write a stored procedure in sql server and the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.