if @prevtype=0
这个条件执行的语句没问题,就是@prevtype=1 时得到的结果总为空
这个条件执行的语句没问题,就是@prevtype=1 时得到的结果总为空
解决方案 »
- 急问 恢复数据库问题
- 请教一条查询语句
- 创建发布服务器的问题
- 关于MSDE的使用,请高手简单指点!
- 求一 sql 语句:select count(P_ID) from Company 的同时,我还想读取另几个字段(比如:company_name,company_address)这样的语句应该
- 如何删除完全相同的记录而只剩下一条
- 求助一个MERGE的问题
- SQLSERVER的SQL语句可以能够调用COM对象里面的方法吗?
- 这个该咋写?
- 两条数据合并成一条
- 高手相助,求一SQL数据库禁用解决方案.50分,在线急等!!!!
- 简单问题:用select得到的记录集,当做一个table,继续在sql语句里使用,应该怎么写?
(
@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
select @keyword='afaf'
select @keyword
----
a(所影响的行数为 1 行)
另外,一旦@prevtype 不等于 0 且不等于 1,存储过程将不返回结果集。
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没有得到值,这是怎么回事?
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)"