首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

哪个大神前来看看小弟我的存储过程

2012-09-25 
哪个大神前来看看我的存储过程declare @PageCount int,@TopicId int,@Num intBEGINselectdistincttop 6t.t

哪个大神前来看看我的存储过程
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
--测试1declare @PageCount int,@TopicId int,@Num intBEGINselect  distinct  top 6  t.topicid,t.title,isnull(t.pic,'../images/pic003.jpg') as picfrom  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--测试2select Top (6*1) BooksId from dbo.T_Books_Order where UserId in(select UserId from dbo.T_Books_Order where BooksId=1)--测试3select Top (6*2) BooksId from dbo.T_Books_Order where UserId in(select UserId from dbo.T_Books_Order where BooksId=1) 

热点排行