• You can implement this with Dynamic SQL as well

    DECLARE@TableName VARCHAR(100), @SQL VARCHAR(1000)

    SET@TableName = 'agent'

    SET@SQL= ' SELECT* '

    + ' FROM ' + @TableName

    + ' WHERE ' + CASE WHEN @TableName IN ( 'product', 'customer' ) THEN 'statecode = 0' ELSE '1=1' END

    EXECUTE ( @SQL )


    Kingston Dhasian

    How to post data/code on a forum to get the best help - Jeff Moden
    http://www.sqlservercentral.com/articles/Best+Practices/61537/