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 2005 Forums
 Transact-SQL (2005)
 query tuning

Author  Topic 

avijit_mca
Posting Yak Master

109 Posts

Posted - 2010-03-03 : 12:23:26
select * from
employee
where basic+bonus >8000

how we make this query performance tuning in where clause

Regards,
avijit

Sachin.Nand

2937 Posts

Posted - 2010-03-03 : 12:26:38
what other columns are there in your "*"?

PBUH
Go to Top of Page

namman
Constraint Violating Yak Guru

285 Posts

Posted - 2010-03-03 : 13:24:37
select * from
employee
where basic+bonus >8000

how we make this query performance tuning in where clause



This one is better
select * from employee where basic > 8000 - bonus

If you create a non-clustered index on "basic" column, then cover the "bonus" column on the index, the above query must better.

If the query has been run milions times a day, you should create a extra column named basicANDBonus that holds value of basic+bonus, then create a non-clustered index on that column.
select * from employee where basicANDBonus > 8000.
Then this query will be supper fast
Go to Top of Page

avijit_mca
Posting Yak Master

109 Posts

Posted - 2010-03-04 : 01:52:02
thanks

Regards,
avijit
Go to Top of Page

David Singleton
Starting Member

35 Posts

Posted - 2010-03-04 : 04:14:57
Wouldn't it be better to create a field BasicWithBonus, populate this as Basic + Bonus, and then index the new field?

David Singleton

Microsoft MVP Dynamics NAV
Go to Top of Page
   

- Advertisement -