Background: There\'s a stored procedure which does \"stuff\" with a temp table of a given name. The procedure is generic in that it inspects the schema of the temp table and
It's a limitation. Dynamic SQL won't work either since #tmp will be created in a new session and immediately lost. For the EXACT snippet as shown, this does the same
CREATE TABLE #test
(
a BIGINT NOT NULL,
b BIGINT NOT NULL
)
IF not (1=1)
ALTER TABLE #test ADD c BIGINT NOT NULL
There cannot be two CREATE .. #name within the same batch, but this will also work in general form
IF (1=1)
BEGIN
CREATE TABLE #test
(
a BIGINT NOT NULL,
b BIGINT NOT NULL
);
END
GO
IF NOT (1=1)
BEGIN
CREATE TABLE #test
(
a BIGINT NOT NULL,
b BIGINT NOT NULL,
c BIGINT NOT NULL
)
END