Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Filtering Date (Show All Records)

Posted on 2013-12-24
2
Medium Priority
?
472 Views
Last Modified: 2013-12-24
Hello,

I filter a SQL statement to allow records to be displayed that sit within a specific date range, i.e. show all records from the last 30 days

WHERE
object_audit_info.action_date >= DateAdd(Day, DateDiff(Day, 0, GetDate()) - @NoOfDays, 0)

I do this by passing an int containing the filter value @NoOfDays, the trouble I now have is how to accommodate where I want to display all records?

At the moment when the user requests this the system passes 0, if there any way of telling the SQL statement not run the where clause if the parameter @NoOfDays contains a 0 ?

Thanks.
0
Comment
Question by:andyw27
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 2000 total points
ID: 39737505
you cna Add OR statement

WHERE
@NoOfDays = 0 OR
object_audit_info.action_date >= DateAdd(Day, DateDiff(Day, 0, GetDate()) - @NoOfDays, 0)
0
 

Author Comment

by:andyw27
ID: 39737519
Brilliant thanks, worked like a charm.
0

Featured Post

Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

662 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question