Creating table with different columns depending on condition (which is SQL version)

51 Views Asked by At

I would like to create a table for statement: DBCC CHECKDB (0) WITH ALL_ERRORMSGS, TABLERESULTS however the result of this statement depends on SQL Server version, in higher versions there are more columns.

Statement:

IF (CAST(SERVERPROPERTY('productversion') AS varchar), 2) > '10'    
    CREATE TABLE #dbcc_output (columns..)
ELSE        
    CREATE TABLE #dbcc_output (different columns..)

This code causes an error:

There is already an object named '#dbcc_output' in the database

Is there a smart way to do it or just check if object exists in ELSE part?

0

There are 0 best solutions below