各位:请帮忙看一下参数的使用???谢谢
CREATE procedure P_Exists
(
@i_tableName varchar(30),
@i_FieldName varchar(30),
@i_FieldValue varchar(30),
@o_flag bit output
)
AS
/*********************************************
DESCRIPTION: 查询表@i_tableName,看是否存在这样的记录:字段@i_fieldName的值为@i_fieldValue。
如果存在,返回1;
否则返回0
Example use: declare @a bit
execute p_Exists 'customer','loginname','logpwd',@a
print @a
*********************************************/
BEGIN
declare @sql varchar(400),
@count int
set @sql='select @count=count(1) from ' + @i_tableName + ' where ' + @i_FieldName + ' = ''' + @i_FieldValue + ''''
--print @sql
exec(@sql)
if (@count=0)
set @o_flag=0
else
set @o_flag=1
end
GO
为什么SQLSERVER能生成此存储过程,但执行时却说:
服务器: 消息 137,级别 15,状态 1,行 1
必须声明变量 '@count'。
可我声明了啊???