0

I have this code in my SQL, however the if statement seems to be not working at all. Every time I run the query below.. I always have an error that says...

Msg 2714, Level 16, State 1, Line 39
There is already an object named '##TEMP1' in the database.

QUERY BELOW...

IF (SELECT COUNT (*) FROM ##TEMP1 WHERE [ACTION] NOT LIKE 'ok' ) >=1
        BEGIN               
                SELECT * INTO ##newtable FROM ##TEMP1 ORDER BY 1 ASC

                Select ' ' = 'MESSAGE' 
                SELECT * FROM ##newtable
        END
    ELSE
        BEGIN
                Select [MESSAGE] = 'MESSAGE' INTO ##newtable
                SELECT * FROM ##newtable
        END

is there any way that the query creates a final table '##temp1' given that the condition is met? So it's either the first begin statement or the second one.

Thank you.

Magpie737
  • 3
  • 1

0 Answers0