我想做一个检查(if 语句),然后创建两个可能的过程之一。
现在我正在尝试在IF EXISTS
语句中使用CREATE PROCEDURE
语句。
CREATE PROCEDURE [dbo].[TestProc]
AS
SET NOCOUNT ON
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER OFF
IF EXISTS (select * from table)
BEGIN
DECLARE @region NVARCHAR(100)
SELECT *
INTO #TempTable
FROM User
...用#TempTable 等做一些事情。
DROP #TempTable
END
ELSE
BEGIN
DECLARE @region NVARCHAR(100)
SELECT *
INTO #TempTable
FROM User
...用#TempTable 等做其他事情
DROP #TempTable
END
我收到以下 2 个错误
There is already an object named 'TempTable' in the database.
The variable name '@region' has already been declared. Variable names must be unique within a query batch or stored procedure.