0

I have one stored procedure MySproc with following two queries

INSERT INTO STG 

SELECT ID,AMT,DATE FROM CUSTOMER

UPDATE STG SET AMT = null

I dont want to run the update everytime I run MySproc. What is the best way to control what I want to run within MySproc?

1
  • Just comment it out. Commented Nov 11, 2014 at 15:25

3 Answers 3

0

Create your procedure as below

CREATE PROCEDURE myPROC @RUNUPDATE INT = 1
AS
BEGIN

INSERT INTO STG 

SELECT ID,AMT,DATE FROM CUSTOMER
IF @RUNUPDATE = 1
    BEGIN
        UPDATE STG SET AMT = null
    END

END

When you run call your proc, you can pass in a value of 1 or 0 depending upon whether you wish to run the update.

Sign up to request clarification or add additional context in comments.

Comments

0

Try this script:

INSERT INTO STG
SELECT ID,AMT=NULL,DATE FROM CUSTOMER

Comments

-1
INSERT INTO STG
SELECT ID,NULL,DATE FROM CUSTOMER

1 Comment

While this code snippet may solve the question, including an explanation really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.