存储过程返回记录总为空,如果修改:

seafarer777 2005-07-19 11:05:06
CREATE PROCEDURE txl_list_user
(
@userid int,
@groupid int,
@StartNum int,
@LeaveNum int,
@prevtype int,
@keyword varchar
)
AS
declare @StrSql varchar(1000)
if @prevtype=0
begin
set @StrSql="select id,realname from (select top "+str(@StartNum)+" id,realname from txl_userinfo where userid="+str(@userid)+" and groupid="+str(@groupid)+" and status=0 order by id desc) a where a.id not in (select top "+str(@LeaveNum)+" ID from txl_userinfo where userid="+str(@userid)+" and groupid="+str(@groupid)+" and status=0 order by id desc)"
end
if @prevtype=1
begin
set @strSql="select id,realname from (select top "+str(@StartNum)+" id,realname from txl_userinfo where userid="+str(@userid)+" and groupid="+str(@groupid)+" and (charindex('+@keyword+',realname)>0 or charindex('+@keyword+',pinyin)>0) and status=0 order by id desc) a where a.id not in (select top "+str(@LeaveNum)+" ID from txl_userinfo where userid="+str(@userid)+" and groupid="+str(@groupid)+" and (charindex('+@keyword+',realname)>0 or charindex('+@keyword+',pinyin)>0) and status=0 order by id desc)"
end
exec(@strSql)
GO
...全文
97 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
seafarer777 2005-07-19
  • 打赏
  • 举报
回复
可以了
set @strSql="select id,realname from (select top "+str(@StartNum)+" id,realname from txl_userinfo where userid="+str(@userid)+" and groupid="+str(@groupid)+" and (charindex('"+@keyword+"',realname)>0 or charindex('"+@keyword+"',pinyin)>0) and status=0 order by id desc) a where a.id not in (select top "+str(@LeaveNum)+" ID from txl_userinfo where userid="+str(@userid)+" and groupid="+str(@groupid)+" and (charindex('"+@keyword+"',realname)>0 or charindex('"+@keyword+"',pinyin)>0) and status=0 order by id desc)"
seafarer777 2005-07-19
  • 打赏
  • 举报
回复
打印出来的语句是这样的
select id,realname from (select top 2 id,realname from txl_userinfo where userid=10000 and groupid=1002 and (charindex('+@keyword+',realname)>0 or charindex('+@keyword+',pinyin)>0) and status=0 order by id desc) a where a.id not in (select top 0 ID from txl_userinfo where userid=10000 and groupid=1002 and (charindex('+@keyword+',realname)>0 or charindex('+@keyword+',pinyin)>0) and status=0 order by id desc)

@keyword没有得到值,这是怎么回事?
seafarer777 2005-07-19
  • 打赏
  • 举报
回复
@StartNum <= @LeaveNum 这种情况不会发生的,程序里有控制的,而且我是在查询分析器调试存储过程的,@StartNum ,@LeaveNum 两个参数我已经指定值了
vivianfdlpw 2005-07-19
  • 打赏
  • 举报
回复
把你的sql语句print出来然后在查询分析器里调试
seafarer777 2005-07-19
  • 打赏
  • 举报
回复
执行@prevtype=1条件时还是得不到相应的结果
子陌红尘 2005-07-19
  • 打赏
  • 举报
回复
单看存储过程似乎没什么问题,一旦@StartNum <= @LeaveNum,返回的结果集将肯定为空;
另外,一旦@prevtype 不等于 0 且不等于 1,存储过程将不返回结果集。
phantomMan 2005-07-19
  • 打赏
  • 举报
回复
varchar 默认长度为1:

declare @keyword varchar
select @keyword='afaf'
select @keyword


----
a

(所影响的行数为 1 行)

paoluo 2005-07-19
  • 打赏
  • 举报
回复
你的存储过程能通过语法检查吗??

SQL没有"的写法吧,只有'。
vivianfdlpw 2005-07-19
  • 打赏
  • 举报
回复
这个问题蛮多的嘛
zlp321002 2005-07-19
  • 打赏
  • 举报
回复
CREATE PROCEDURE txl_list_user
(
@userid int,
@groupid int,
@StartNum int,
@LeaveNum int,
@prevtype int,
@keyword varchar(100) --定义长度
)
AS
declare @StrSql varchar(1000)
if @prevtype=0
begin
set @StrSql="select id,realname from (select top "+str(@StartNum)+" id,realname from txl_userinfo where userid="+str(@userid)+" and groupid="+str(@groupid)+" and status=0 order by id desc) a where a.id not in (select top "+str(@LeaveNum)+" ID from txl_userinfo where userid="+str(@userid)+" and groupid="+str(@groupid)+" and status=0 order by id desc)"
end
if @prevtype=1
begin
set @strSql="select id,realname from (select top "+str(@StartNum)+" id,realname from txl_userinfo where userid="+str(@userid)+" and groupid="+str(@groupid)+" and (charindex('+@keyword+',realname)>0 or charindex('+@keyword+',pinyin)>0) and status=0 order by id desc) a where a.id not in (select top "+str(@LeaveNum)+" ID from txl_userinfo where userid="+str(@userid)+" and groupid="+str(@groupid)+" and (charindex('+@keyword+',realname)>0 or charindex('+@keyword+',pinyin)>0) and status=0 order by id desc)"
end
exec(@strSql)
GO
vivianfdlpw 2005-07-19
  • 打赏
  • 举报
回复
@keyword varchar

================>

@keyword varchar(20)
zlp321002 2005-07-19
  • 打赏
  • 举报
回复
--@keyword varchar 要定义长度
seafarer777 2005-07-19
  • 打赏
  • 举报
回复
if @prevtype=0
这个条件执行的语句没问题,就是@prevtype=1 时得到的结果总为空

34,590

社区成员

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

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