Parameters to SQL not work sometimes

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Parameters to SQL not work sometimes

    :confused; Here is the stored proc. I send a value for @OrgAction for the if
    statements. The first statement runs and returns data. Using the second
    statement results in error message:

    Error Executing Database Query.
    [Macromedia][SQLServer JDBC Driver][SQLServer]Must declare the variable
    '@StartDate'.

    the Org_Code code in the WHERE clause works OK in other places. I think my
    date formating is correct for the view being used.

    CREATE PROCEDURE dbo.spr_EvalTrnDates(
    @ListItems varchar(100),
    @OrgAction varchar (10),
    @StartDate varchar(10)=NULL,
    @EndDate varchar (10)=NULL
    )
    AS
    SET NOCOUNT ON

    /*RS1 Find people who were sent an evaluation and have not returned it. Org
    Code is
    in thousands groups, eg. 1000 to 1999. Sent evaluation has date range
    criteria.*/


    IF @OrgAction = 'EvalSent'
    BEGIN
    SELECT *
    FROM dbo.vwGetEvalSentRptData
    WHERE (Last_Eval IS NULL)AND (Eval_Notice_Sent_Date_yy BETWEEN @StartDate AND
    @EndDate) AND (Org_Code LIKE @ListItems + '%')
    ORDER BY Org_Code, Employee_Name

    END

    /*RS2 Find people who were sent an evaluation and have not returned it. Org
    Code is
    in a list of individual Org_Code numbers selected by the user.
    Sent evaluation has date range criteria.*/


    IF @OrgAction = 'EvalSentxM'
    BEGIN
    DECLARE @sSQLxM2 varchar(4000)
    SET @sSQLxM2 = 'SELECT *
    FROM dbo.vwGetEvalSentRptData
    WHERE (Last_Eval IS NULL)AND (Eval_Notice_Sent_Date_yy BETWEEN @StartDate AND
    @EndDate) AND
    (Org_code in (''' + REPLACE(@ListItems,',',''',''') + '''))
    ORDER BY Org_Code, Employee_Name'
    EXEC (@sSQLxM2)
    END
    .......... (More of the same.)
    GO

    Jim B2 Guest

  2. Similar Questions and Discussions

    1. #34564 [Asn->Csd]: reference (in/out) parameters don't work
      ID: 34564 Updated by: wharmby@php.net Reported By: milman at gmx dot de -Status: Assigned +Status: ...
    2. #34564 [Com]: reference (in/out) parameters don't work
      ID: 34564 Comment by: wharmby at uk dot ibm dot com Reported By: milman at gmx dot de Status: Assigned Bug...
    3. Open parameters do not work
      The open parameters specified in URL (e.g. <http://partners.adobe.com/asn/acrobat/sdk/public/docs/PDFOpenParams.pdf#page=6)> do not work (neither in...
    4. 'out' parameters work outside of .NET?
      Hello, In .NET C# it is possible to define a parameter to a web service method as 'out'. The web service method is expected to set the value of...
    5. passing parameters to a script doesn't work
      Hi, I'm trying to pass parameters to a PHP script and it's not working. Whilst this is the first time I've tried to use this, I'm basically...
  3. #2

    Default Re: Parameters to SQL not work sometimes

    Your second statement is dynamic SQL. The variables are not availble to the
    statement at the level that EXEC() runs.

    Change your SET statement:

    SET @sSQLxM2 = 'SELECT *
    FROM dbo.vwGetEvalSentRptData
    WHERE (Last_Eval IS NULL)AND (Eval_Notice_Sent_Date_yy BETWEEN
    '''+@StartDate+''' AND '''+@EndDate+''') AND
    (Org_code in (''' + REPLACE(@ListItems,',',''',''') + '''))
    ORDER BY Org_Code, Employee_Name'

    HTH,


    philh Guest

  4. #3

    Default Re: Parameters to SQL not work sometimes

    philh - This works perfectly. Thanks
    Jim B2 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139