0

I'm struggling with how to pass datetime parameters into a stored procedure. This is the example I'm working with. I commented out the declaring of the variables, because if I declare them it doesn't let me pass them in when I execute, but if I don't declare them, I can't execute it. Please help!

    --The Create Procedure Code
    CREATE PROCEDURE users.my_test
    AS

    --declare @startdatetime datetime = '03-20-2019'
    --declare @enddatetime datetime = '05-20-2019'
    SELECT datediff(mi,@startdatetime,@enddatetime)
    GO

    --The execution Code
    exec users.my_test
    @startdatetime = '03-31-2019', @enddatetime = '07/03/2019'
    GO
1
  • 1
    What you're doing here is defined two internal variables for the stored procedure - those are not parameters that can be set when calling the procedure! Parameters must be declared right after the stored procedure name, and with a leading @ Commented Aug 1, 2019 at 5:07

1 Answer 1

1

You can add parameter like this

CREATE PROCEDURE users.my_test
 @startdatetime datetime ,
 @enddatetime datetime 
AS

--declare @startdatetime datetime = '03-20-2019'
--declare @enddatetime datetime = '05-20-2019'
SELECT datediff(mi,@startdatetime,@enddatetime)
GO
Sign up to request clarification or add additional context in comments.

Comments

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.