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 2012 Forums
 Transact-SQL (2012)
 rewrite query

Author  Topic 

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2015-05-04 : 21:30:03
I am having performance issue for the below condition and please help me in resolving the issue by rewriting the query to improve the perforomance..

there is already non clusterd index created on studentadmissiondate, studentRecorddate but still had performance issues.


where ( studentcountrycode = @studentcountrycode ) And
((Studentreportindicator = 1 and studentadmissiondate between
@reportstartdate and @reportstartdate)
OR (Studentreportindicator = 2 and studentRecorddate between
@reportstartdate and @reportstartdate))



Thanks for your help in advance

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2015-05-04 : 21:48:30
Show us the execution plan and stats io output. You likely need a better composite index, possibly with include columns. You didn't post the whole query, so it's really hard to help.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

jleitao
Posting Yak Master

100 Posts

Posted - 2015-05-05 : 06:41:54
will not solve your problem but why you have this?

studentadmissiondate between @reportstartdate and @reportstartdate

you can replace it by studentadmissiondate = @reportstartdate

the same "problem here:

studentRecorddate between @reportstartdate and @reportstartdate



------------------------
PS - Sorry my bad english
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2015-05-05 : 09:42:33
I would use a UNION instead of the OR. 9-times-out-of-10 that fixes slow running queries.
Go to Top of Page
   

- Advertisement -