472,133 Members | 1,196 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,133 software developers and data experts.

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 2273
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 leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.