Hello,
Very strange we faced at work yesterday.
there is code where the select contains a cast (columnid as int)
Now this works on one server and another server fails, its the same data on both the servers. There is filter on the select which filters out the non numeric values and then the select should convert the numeric values from teh filters and joins into Int.
BUt the server A works fine. but server B tries to do it differently the aggregates are done first and the conversion and then the filters are applied so the select fails because its tryong to connvert varchar to int.
here is the sample sql query.
SELECT MIN(CAST(EnId .ccId as int)) FirstCCid
FROM
dbo.en1 en1
INNER JOIN dbo.EnId EnId ON En1.ObjId = Enid.EncObjId
INNER JOIN dbo.IdDef IdDef ON IdDef.ObjId = EnId.IdDefObjId
WHERE
IdDef.TypeCd = 10 ---- Here its filtering only to get numeric values
GROUP BY En1.CommonId
HAVING cast(CONVERT(varchar(254),min(En1.CrDTime),101) as datetime) >= '12/01/2012'
AND cast(CONVERT(varchar(254),min(En1.CrDTime),101) as datetime) <= '12/31/2012'
We are thinking something how the optimizer decides the plan is being changed from Prod A to Prod B.
Can anyone throw some light. May be Statistics are out of .. hmm dont know.. what to think here.