bibi92
asked on
optimize where clause on a query
Hello,
I have checked execution plan.
How can I optimize this query :
Thanks
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'
Thanks
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
have you tried casting the AND clause as a date?
CAST( cast( year(current_timestamp)-2 as char(4)) +'0101' AS DATETIME)