>Thanks a lot for your help, your script seems logically but execution time is >almost the same > >Total execution time: 0:01:59 (hh:mm:ss) Script execution finished. > >I debug and the execution of the procedure is not one time, now it is executed >19593 times
OK, let's try brute force: SELECT a.date, a.id FROM PR_GET_SOLD(2013,1) x LEFT JOIN mytable1 a ON x.numb = p.numb WHERE a.year = 2013 UNION SELECT a.date, a.id FROM mytable1 a WHERE a.year = 2013 AND a.month = 1 Providing a.id is unique, this should get the right result (UNION, as opposed to UNION ALL only returns unique rows) and it should not take two minutes! Sorry for not knowing of a more elegant solution, I use stored procedures far too rarely. Set
