John,
In addition to what Sergey said, you should always create temp table using the CREATE TABLE command then INSERT the records into it. When you dynamically create tables using the SELECT...INTO command, it locks the master db while the entire select statement is being created which can cause problems if it takes a while, ie, users cannot create connections, etc.
...
CREATE TABLE #mytable
(column1 type
.... )
IF condition = 'A'
INSERT INTO #mytable SELECT * FROM inserted
ELSE
INSERT INTO #mytable SELECT * FROM inserted WHERE abc = 'A'
...
Kurt
>Hi,
>I have trigger code as below. SQL Server complaint "There is already an object named "#mytable" in the database. But I already restart the server.
>
>
CREATE PROCE myTrigger ON mytable FOR INSERT
>AS
>BEGIN
> IF condition = 'A'
> SELECT * INTO #mytable FROM inserted
> ELSE
> SELECT * INTO #mytable FROM inserted WHERE abc = 'A'
>END
>
>If I renamed one of them, the error will be gone.
>
>Please advice.
>
>Thank you