SQL error on scaler variable

  • Hi,

    I need help on SQL getting an error when pasting a stored procedure "error 42000 must declare the scalar variable "@DischargeEndDate" for the following code

    PROCEDURE [dbo].[DR_Premier_PO_O] (@DischargeStartDate DateTime, @DischargeEndDate DateTime)

    AS

    DECLARE @vStartDate as varchar(30), @vEndDate as varchar(30)

    SET @DischargeEndDate = DateAdd(mi,-1,@DischargeEndDate)

    SET @vStartDate = CONVERT(varchar(30), @DischargeStartDate, 101)

    SET @vEndDate = CONVERT(varchar(30), @DischargeEndDate, 101) + ' 23:59:58'

  • You need to specify parameter is nullable or not

    CREATE PROCEDURE [dbo].[DR_Premier_PO_O] (@DischargeStartDate DateTime =NULL, @DischargeEndDate DateTime =NULL)

    AS

    DECLARE @vStartDate as varchar(30), @vEndDate as varchar(30)

    SET @DischargeEndDate = DateAdd(mi,-1,@DischargeEndDate)

    SET @vStartDate = CONVERT(varchar(30), @DischargeStartDate, 101)

    SET @vEndDate = CONVERT(varchar(30), @DischargeEndDate, 101) + ' 23:59:58'

  • CREATE PROCEDURE [dbo].[DR_Premier_PO_O]...

    you are just missing the word create; after that my syntax issues went away.

    i got 4 errors total, and only the last matched your error.

    Msg 156, Level 15, State 1, Line 1

    Incorrect syntax near the keyword 'PROCEDURE'.

    Msg 137, Level 15, State 2, Line 7

    Must declare the scalar variable "@DischargeEndDate".

    Msg 137, Level 15, State 2, Line 9

    Must declare the scalar variable "@DischargeStartDate".

    Msg 137, Level 15, State 2, Line 10

    Must declare the scalar variable "@DischargeEndDate".

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thank You

  • CREATE statement gives me an error which says "you do not have access to live-db". But when I run other reports I do not have any problem.

  • CREATE statement gives me an error which says "you do not have access to live-db". But when I run other reports I do not have any problem.

  • Sounds like you don't have permissions to create a stored procedure.

  • Thank You

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply