日期:2014-05-18  浏览次数:20424 次

这个存储过程为什么读不出数据啊?郁闷
CREATE   PROCEDURE   PrSerchTag  
@tag   varchar(20)
AS
declare   @id   int
declare   @tagid   int
--declare   @bool   char(4)
begin
  if   exists   (select     tagid   from   tagtable   where   tagname   like     '% '+@tag+ '% ')
          begin
             
                      select   @tagid   =     tagid   from   tagtable   where   tagname   like       '% '+@tag+ '% '
                select   @id=   rizhiid   from   rizhitagtable   where   tagid   =@tagid
                select   rizhiid,yonghuname,rizhititle,substring(rizhicontent,0,200)+ '...... '   as   'rizhicontent ',rizhitime,touchnum,yonghuid   from   rizhiview   where   rizhiid=@id
        end
  else
                return   (0)


end

------解决方案--------------------
if exists (select tagid from tagtable where tagname like '% '+@tag+ '% ')
begin

.....
-->


if exists (select tagid from tagtable where tagname like '% '+@tag+ '% ')
begin

select 1 --加上这条,执行后看看有没有执行到这句。
.....
------解决方案--------------------
select @tagid = tagid from tagtable where tagname like '% '+@tag+ '% '
select @id= rizhiid from rizhitagtable where tagid =@tagid

tagid应可能有多个值吧,能这样输给@tagid么?
rizhiid也有可能有多个值的,不能这样给@id输值.
------解决方案--------------------
@tagid只能是最后的一个tagid的值
@id也只能是rizhiid的最后一个值
------解决方案--------------------
@tagid,@id 只读出一个值,建议楼主写成游标
------解决方案--------------------
similarly answer below:

HTTP://www.ebigear.com/Fund/PlayNews.php?NewsID=28340&ID=285885