Re: If Statement to determine WHERE condition in SQL Query
- From: Hugo Kornelis <hugo@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 12 May 2005 23:09:19 +0200
On Thu, 12 May 2005 07:07:39 -0700, Rhonda Fischer wrote:
>Hello,
>
>The @parameters that I am receiving into my SQL query in SQL Serer 2000
>Reporting Services are based on user selection from a drop down combo box.
>If the user selects a name it will return an integer. An alternative to
>selecting a single name the user can select 'ALL' of which will return a -1
>or maybe '*' if allowed. I would like an if stmt to determine if a criteria
>be added to the query or not. Can I do this, is there anyway of achieving the
>same thing?
>
>SELECT Forename, Username, Description
>FROM Audit
>WHERE Date >= @Param_StartDate
>AND Date < @Param_EndDate
>if @Param_UserKey <> -1
> AND UserID =@Param_UserKey 'continue to add last line of SQL stmt
Hi Rhanda,
Try this one:
SELECT Forename, Username, Description
FROM Audit
WHERE Date >= @Param_StartDate
AND Date < @Param_EndDate
AND ( @Param_UserKey = -1
OR UserID = @Param_UserKey )
>There are two more @Parameters to test if the 'ALL' option is selected also
>not
>sure I can neatly handle this. @Param_RecordType and @Param_ModuleNo.
I'm not sure what you mean. If you don't see how to adapt the above
query to handle this case, then please post more specific information.
(Check out www.aspfaq.com/5006 for the best way to post questions).
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)
.
- References:
- If Statement to determine WHERE condition in SQL Query
- From: Rhonda Fischer
- If Statement to determine WHERE condition in SQL Query
- Prev by Date: Re: If Statement to determine WHERE condition in SQL Query
- Next by Date: Set a dinamic varable in query
- Previous by thread: Re: If Statement to determine WHERE condition in SQL Query
- Next by thread: Set a dinamic varable in query
- Index(es):
Relevant Pages
|
|