在存储过程中:
IF (condition1)
SELECT * INTO #temp FROM table1 WHERE name = 'Dave'
ELSE
SELECT * INTO #temp FROM table1 WHERE name = 'Greg'
创建存储过程时,它会显示“数据库中已存在名为'#temp'的对象”。它必须认为我正在创建两次相同的临时表。
周围有好方法吗?
我知道我可以INSERT INTO #temp(....), 但是有很多字段,我不想重新输入它们。
答案 0 :(得分:2)
如果这很傻就不要-1
请告诉我,我会删除
我不知道你的病情的性质1
为什么不呢?
SELECT * INTO #temp
FROM table1
WHERE ( condition1 and name = 'Dave')
OR (!condition1 and name = 'Greg')
答案 1 :(得分:1)
试试这个:
SELECT * INTO #temp FROM table1 WHERE 1 = 0
IF (condition1)
INSERT INTO #temp SELECT * FROM table1 WHERE name = 'Dave'
ELSE
INSERT INTO #temp SELECT * FROM table1 WHERE name = 'Greg'
select into不会返回任何行,但它会使临时表具有正确的列。
答案 2 :(得分:0)
你试过了吗?
If (condition1)
INSERT INTO #temp
SELECT * FROM table1 where name = 'Dave'
ELSE
INSERT INTO #temp
SELECT * FROM table1 where name = 'Greg'