各位:请帮忙看一下参数的使用???谢谢

prcgolf 2003-04-16 09:28:48
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'。
可我声明了啊???
...全文
67 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
hansong_ll 2003-04-17
  • 打赏
  • 举报
回复
pengdali(大力)
为什么会出现这样的错误?
服务器: 消息 214,级别 16,状态 2,过程 sp_executesql,行 18
过程需要参数 '@statement' 为 'ntext/nchar/nvarchar' 类型。

第18行为:
SET @sSQL=N'SELECT @sMLSH=MAX(' + @sFieldName + ') FROM ' + @sTableName + ' WHERE ' + @sFieldName + ' LIKE %' + '' + @sLSH + '' + '%'
EXEC sp_executesql @sSQL,N'@sMLSH nvarchar(20) output',@sMaxLSH output
prcgolf 2003-04-16
  • 打赏
  • 举报
回复
大力领分啊!!

非常感谢啊!!!
pengdali 2003-04-16
  • 打赏
  • 举报
回复
@count 是外部的参数,exec中没有办法传递出来,只能用sp_executesql
pengdali 2003-04-16
  • 打赏
  • 举报
回复
页面上有个“管理”的按钮!
prcgolf 2003-04-16
  • 打赏
  • 举报
回复
我怎么给大力分啊???
我第一次发帖子啊??

prcgolf 2003-04-16
  • 打赏
  • 举报
回复
可是为什么要这么要用变量啊???
能详细说一下嘛??

谢谢
prcgolf 2003-04-16
  • 打赏
  • 举报
回复
非常感谢!!!
pengdali 2003-04-16
  • 打赏
  • 举报
回复
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 nvarchar(4000),
@count int
set @sql=N'select @count=count(1) from ' + @i_tableName + ' where ' + @i_FieldName + ' = ''' + @i_FieldValue + ''''

exec sp_executesql @sql,N'@count int output',@count output

if (@count=0)
set @o_flag=0
else
set @o_flag=1
end
pengdali 2003-04-16
  • 打赏
  • 举报
回复
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 nvarchar(4000),
@count int
set @sql=N'select @count=count(1) from ' + @i_tableName + ' where ' + @i_FieldName + ' = ''' + @i_FieldValue + ''''

exec sp_executesql @sql,N'@count int output',@id output

if (@count=0)
set @o_flag=0
else
set @o_flag=1
end
GO

34,838

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧