Solved

Filtering Date (Show All Records)

Posted on 2013-12-24
2
424 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
2 Comments
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now