我有一个问题,我似乎没有得到解决。如果我从完整代码中删除以下部分,则存储过程在创建时会引发错误:
-- SET @ResultType = 'Success'
-- SET @ResultMessage = 'Environment Created'
我该如何解决这个问题?
CREATE PROC [dbo].[usp_InsertEnvironment]
@EnvironmentName nvarchar(50),
@EnvironmentDescription nvarchar(250),
@ResultType as Nvarchar(50) OUTPUT,
@ResultMessage as Nvarchar(250) OUTPUT
AS
--SET NOCOUNT ON
--SET XACT_ABORT ON
BEGIN TRANSACTION
IF NOT EXISTS(SELECT * FROM dbo.Environment WHERE EnvironmentName = @EnvironmentName)
--This environmentName does not exists, so insert...
INSERT INTO dbo.Environment
SELECT @EnvironmentName, @EnvironmentDescription
-- I get an error if I decomment the 2 lines underneath :-(
--SET @ResultType = 'Success'
--SET @ResultMessage = 'Environment Created'
ELSE
--This environmentName does not exists so throw error
SET @ResultType = 'Error'
SET @ResultMessage = 'Environment already exists'
COMMIT