• The parser doesn't care about logical processing. It sees the same create temp table and throws up its hands. Maybe you can change your logic a little bit to avoid dynamic sql. In your comments it sounds like you have the same columns in 2005/2008 but with 2012 you need to simply add some columns? If so, just create your 2005 version of the table and then add whatever columns you need for 2012.

    DECLARE @ProdVersion VARCHAR(4)

    SELECT @ProdVersion = CASE

    WHEN SUBSTRING(CAST(SERVERPROPERTY('ProductVersion') AS VARCHAR(20)), 1, 3) = '9.0'

    THEN '2005'

    WHEN SUBSTRING(CAST(SERVERPROPERTY('ProductVersion') AS VARCHAR(20)), 1, 3) = '10.'

    THEN '2008'

    WHEN SUBSTRING(CAST(SERVERPROPERTY('ProductVersion') AS VARCHAR(20)), 1, 3) = '11.'

    THEN '2012'

    END

    CREATE TABLE #DBCC_OUTPUT

    (

    [Error] INT NULL

    )

    IF (@ProdVersion = '2012')

    BEGIN

    --Alter the table with extra columns added in 2012

    alter TABLE #DBCC_OUTPUT

    add YourNewColumn varchar(10)

    alter TABLE #DBCC_OUTPUT

    add YourOtherColumn int

    END

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/