• Hi,

    thanks to all for their help and tips.

    You are right, the RS statement still had the index hint, but it did not help. The result is the same without the index hint.

    You are also right, that there are slight differences. Yes, the date is hard coded as string in managements studio, but is a datetime type in RS. I hope this does not make a difference.

    The date part of the statement looks a little bit strange, I know. The original data has a timestamp with hour, minute and second, but we are only interested in the data for the whole day. I read about this little trick somewhere (maybe here at SQLCentral...). But I am sure the index works with this, because without it, the same statement takes some minutes to finish...

    I am happy with the result now. All I want to understand is, why is SQL Server 2005 behaving differently if the statement is executed directly or in a stored procedure. I will search the web for some more information.

    Regards

    Oliver