Link to home
Start Free TrialLog in
Avatar of bibi92
bibi92Flag for France

asked on

optimize where clause on a query

Hello,

I have checked execution plan.
How can I optimize this query :
SELECT 
[SplitId],[PKey],[affId],[SalesKey]  ,[Trader]   ,[NetBro] ,[Ccy] ,[NetBroFuncCcy] ,[FuncCcy] ,[Side] ,[NetBroNoDiscount]
FROM   [dbo].[FI_Splits]
WHERE affDate<CAST(ROUND(CAST(getdate() AS float)-0.25,0)AS Datetime)
   and affDate > cast(   year(current_timestamp)-2 as char(4)) +'0101' 

Open in new window


Thanks
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

do you have an index on affDate?

have you tried casting the AND clause as a date?
CAST( cast(   year(current_timestamp)-2 as char(4)) +'0101' AS DATETIME)
For starters, the WHERE clause is doing a comparison with both a datetime and a character values?  That would mean implicit conversion, possibly for every row.

Better to do your formulas in scalar variables of the same data type, then refer to those variables in your WHERE clause.
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial