MS SQL - User Selected Parameters

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tamra
    New Member
    • Nov 2010
    • 1

    MS SQL - User Selected Parameters

    We are modifying a report that allow users to select just one value from 1 to 13 (numeric). (No multiple selections allowed.)

    I would like to name this parameter as @n

    The value is based on this similar query.

    Select DateAdd(Month, 3, @StartDate)


    The original declaration is:

    DECLARE @StartDate AS DateTime
    Set @StartDate = DateAdd(Month, DateDiff(Month, 0, GetDate()) - 1, 0)


    -------------------------------------------------

    The ideal query is like this:

    Select DateAdd(Month, @n, @StartDate)

    User will be prompted to select a parameter value from 1 to 13. If I select 5, it will be equivalent to:

    Select DateAdd(Month, 5, @StartDate)


    Then, this query will be executed based on the value selected.

    I declare @n as numeric. If it was incorrect, please let me know. Thanks.

    ---------------------------------------

    When I first declared and executed, it failed on scalar value.

    Declare @n as numeric
    --Set @n ???? --- Please advise.
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    When you say "user will be prompted" are you talking about some sort of form or GUI? If you are and the StartDate value is available on that time, calculate it on the front-end and not the back-end.

    Good Luck!!!

    ~~ CK

    Comment

    Working...