Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Multiple condition in where clause

Author  Topic 

Villanuev
Constraint Violating Yak Guru

478 Posts

Posted - 2015-04-29 : 03:58:08
Hi May I ask on how to work on this in SSRS/SQL Query. I have a query that need to have a filter condition using Modifieddate between @fromdate and @todate and @employeeNumber while the other choices is to filter if modifieddate > @fromdate and @employeeNumber.

basically if @todate is empty will do the
this filter condition

modifieddate > @fromdate and @employeeNumber

while if @todate is not empty will do this
Modifieddate between @fromdate and @todate and @employeeNumber


Select
* From sample
Where modifieddate > @fromdate and @employeeNumber

or

Modifieddate between @fromdate and @todate and @employeeNumber

Thank you in advance.

stepson
Aged Yak Warrior

545 Posts

Posted - 2015-04-29 : 04:11:49
[code]
Select
* From sample
Where (
(modifieddate > @fromdate AND @todate IS NULL)
or
(Modifieddate between @fromdate and @todate)
)
and @employeeNumber
[/code]


sabinWeb MCP
Go to Top of Page

Villanuev
Constraint Violating Yak Guru

478 Posts

Posted - 2015-04-29 : 04:34:05
Thank you. I Run the SSRS and got this message. Please enter a value for the parameter 'todate' the parameter cannot be blank. what should i do in the @todate parameter. thanks.
Go to Top of Page

stepson
Aged Yak Warrior

545 Posts

Posted - 2015-04-29 : 04:49:54
Try to check , for parameters , the <ALLOW NULL VALUES> and/or the <Default Values> to NULL ,


sabinWeb MCP
Go to Top of Page

Villanuev
Constraint Violating Yak Guru

478 Posts

Posted - 2015-04-29 : 04:58:47
Yes stepson. I tick the allow null value and its working now. Thank you very much.
Go to Top of Page

stepson
Aged Yak Warrior

545 Posts

Posted - 2015-04-29 : 05:02:25
You're welcome!


sabinWeb MCP
Go to Top of Page
   

- Advertisement -