如下这个存储过程为什么会出错?
ALTER PROCEDURE [dbo].[CaCardNoAndTerminalType_Check]
@iResult int output,
@CaCardNo varchar(50),
@terminalType int
AS DECLARE
@count int
DECLARE
@sql nvarchar(500) select @count=count(*) from TerminalDevice_Table where CaCardNo = @CaCardNo and Category = @terminalType if(@count=1)
set @iResult=1
else
set @iResult=-1
ALTER PROCEDURE [dbo].[CaCardNoAndTerminalType_Check]
@iResult int output,
@CaCardNo varchar(50),
@terminalType int
AS DECLARE
@count int
DECLARE
@sql nvarchar(500) select @count=count(*) from TerminalDevice_Table where CaCardNo = @CaCardNo and Category = @terminalType if(@count=1)
set @iResult=1
else
set @iResult=-1
@iResult int output,
@CaCardNo varchar(50),
@terminalType int
AS DECLARE
@count int
DECLARE
@sql nvarchar(500) select @count=count(*) from TerminalDevice_Table where CaCardNo = @CaCardNo and Category = cast(@terminalType as varchar(50))if(@count=1)
set @iResult=1
else
set @iResult=-1
@iResult int output,
@CaCardNo varchar(50),
@terminalType int
AS
begin
DECLARE
@count int
DECLARE
@sql nvarchar(500) select @count=count(*) from TerminalDevice_Table where CaCardNo = @CaCardNo and Category = @terminalType if(@count=1)
set @iResult=1
else
set @iResult=-1
end
@iResult int output,
@CaCardNo varchar(50),
@terminalType int
AS DECLARE
@count int
DECLARE
@sql nvarchar(500) SET @sql='SELECT @count=count(*)
from
TerminalDevice_Table
where CaCardNo = '''+@CaCardNo+''' and Category ='+LTRIM(@terminalType)+''
SP_EXECUTESQL
@SQL,'@count int ',@count OUTPUT
if(@count=1)
set @iResult=1
else
set @iResult=-1