• Hunterwood (2/23/2010)


    Have you ever seen a performance problem using the code bellow (copied from the article)?

    IF ( SELECT COUNT(*) FROM .... WHERE ...) > 0

    BEGIN

    ...etc

    END

    Not on SQL 2005/2008. It may be that there's a difference in earlier versions that has since changed. In 2005/2008, the parser/optimiser is smart enough to realise that the above construct is an EXISTS, phrased differently.

    If the count and the IF are separate statements, then there is an obvious and blatant performance difference

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass