Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

What is the fastest way to manage date filtering within a query?

$
0
0
I have a dynamic SQL query that uses various indexes and views.When a user wants to filter records based on last one day, last one week, last 30 days ...etc.. i use the following code:@date is an integer.begindate is datetime format.begindate > cast(((select dateadd(d,@Date,GETDATE()))) as varchar(20)) The above code slows my query performance by at least 400%! Would it be faster to add a computed column to my table, using the suggested method in the link below? http://stackoverflow.com/questions/15998830/auto-computed-column-in-sql-server-2012Then i could add an indexed view to improve performance, or can this be done another way?Thanks

Viewing all articles
Browse latest Browse all 3145

Trending Articles