469,097 Members | 1,602 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,097 developers. It's quick & easy.

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.
Nov 3 '10 #1
1 2221
2,878 Expert 2GB
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
Nov 3 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

13 posts views Thread by Nathaniel Maier | last post: by
1 post views Thread by Jeff S | last post: by
9 posts views Thread by helimeef | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by kglaser89 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.