日期:2014-05-17  浏览次数:20410 次

哪个大神前来看看我的存储过程
declare @PageCount int,
@TopicId int,
@Num int
BEGIN
select
  distinct
  top 6 
t.topicid,
t.title,
isnull(t.pic,'../images/pic003.jpg') as pic
from 
dbo.T_Novel_Topic t,
  dbo.T_Books_Order o
  where 
  o.OrderType=2 and
  o.UserId in (select UserId from dbo.T_Books_Order where BooksId=1) and
  o.BooksId <> 1 and
  o.BooksId not in (select Top (6*0) BooksId from dbo.T_Books_Order where UserId in(select UserId from dbo.T_Books_Order where BooksId=1)) and
  o.BooksId=t.topicid and 
  o.Status=1  
   
END


红字的那个地方有问题呀 如果 6*1 显示的条数 跟6*2一样

------解决方案--------------------
你的记录一共有多少条啊
如果少于6条那显示一样很正常
------解决方案--------------------
加order by试试看。
------解决方案--------------------
你自己作个测试就可以知道问题在哪了
SQL code

--测试1
declare @PageCount int,
@TopicId int,
@Num int
BEGIN
select
  distinct
  top 6  
t.topicid,
t.title,
isnull(t.pic,'../images/pic003.jpg') as pic
from  
dbo.T_Novel_Topic t,
  dbo.T_Books_Order o
  where  
  o.OrderType=2 and
  o.UserId in (select UserId from dbo.T_Books_Order where BooksId=1) and
  o.BooksId <> 1 and
--  o.BooksId not in (select Top (6*0) BooksId from dbo.T_Books_Order where UserId in(select UserId from dbo.T_Books_Order where BooksId=1)) and
  o.BooksId=t.topicid and  
  o.Status=1   
    
END
--测试2
select Top (6*1) BooksId from dbo.T_Books_Order where UserId in(select UserId from dbo.T_Books_Order where BooksId=1)

--测试3
select Top (6*2) BooksId from dbo.T_Books_Order where UserId in(select UserId from dbo.T_Books_Order where BooksId=1)