• Luis Cazares (8/29/2012)


    Have you tried a JOIN instead of the IN?

    I've read there can be unexpected problems with cross-server queries.

    SELECT --USE DISTINCT if there are multiple rows in vwCRMServiceProviderAccess

    SP.[ServiceProviderGuid],

    SP.[ServiceProviderTypeGuid],

    SP.[ServiceProviderName],

    SP.[ServiceProviderId],

    SP.[MainPlant],

    SP.[ServiceProviderParentGuid]

    FROM ServiceProvider SP

    JOIN vwCRMServiceProviderAccess SPA ON SP.[ServiceProviderGuid] = SPA.[ServiceProviderGuid]

    WHERESPA.[UserGuid] = '4D569648-C703-47BA-BF66-D8E39F5C9D49'

    Yep. I did the same thing you did here Luis, and it returns in 1 second. Quite an improvement, however the developers are telling me that this is a piece of code written by some 3rd party consultants long ago, and everyone is leery about making any direct modifications to their code.

    Apparently, this query crossed over a threshhold of some kind on Monday night and began timing out. When I run the query in an SSMS window, it returns in 33 seconds. I think that the application is timing out at the 30 second mark.

    My boss has asked me to research "why" this has just begun failing. I cannot answer that and was hoping to be able to figure out a way to answer his question. It puzzles me that either of the queries can be run by themselves and both return within a second, but when combined using the IN expression, it suddenly takes 33 seconds.