sql查询的奇怪问题????

usun82 2009-10-20 09:34:39
真是服了,昨天写了个存储过程,遇到了一个奇怪的问题
我用select * from RE_NewsColumn_NewsTopics 从表中查询有3条记录,然后我把写的存储过程复制到这个查询分析器下,在查他就变成一条记录了,不知道大家遇到过这种问题没有,是什么原因???
那个存储过程是select * from RE_NewsColumn_NewsTopics
declare @conditions varchar(20),@values varchar(100),@startIndex int,@endIndex int
set @conditions = ''
set @values = ''
set @startIndex = 1
set @endIndex = 1

set nocount on
declare @indextable table(id int identity(1,1),nid int)
set rowcount @endIndex
if(@conditions = '')
begin
insert into @indextable(nid) select TopicsID from NewsTopics order by TopicsID desc

select c.ColumnName as ColumnName,a.TopicsID as TopicsID,a.TopicsKeyWord as TopicsKeyWord,a.Description as Description,a.TopicsName as TopicsName,a.SubDate as SubDate,a.Operator as Operator
into #temp1
from dbo.NewsTopics a
join RE_NewsColumn_NewsTopics b on a.TopicsID=b.TopicsID
join NewsColumn c on b.ColumnID = c.ColumnID

select TopicsName,TopicsID, ColumnName = stuff((select ',' + ColumnName from #temp1 t where TopicsID = #temp1.TopicsID for xml path('')) , 1 , 1 , '')
,TopicsKeyWord,Description,SubDate,Operator
into #temp01
from #temp1
group by TopicsName,TopicsID,TopicsKeyWord,Description,SubDate,Operator

select * from #temp01 a

inner join @indextable t on
a.TopicsID=t.nid
where t.id between @startIndex and @endIndex order by t.id
select * from RE_NewsColumn_NewsTopics
drop table #temp1
drop table #temp01
end
涉及到的表的脚本太长,如果大家测试我把表的脚本也发上来,谢谢帮忙解决!!!
...全文
37 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
usun82 2009-10-20
  • 打赏
  • 举报
回复
Thank you,见识了!
小宏 2009-10-20
  • 打赏
  • 举报
回复

set rowcount @endIndex
--set rowcount和select top 效果是类似的,如果你@endIndex 为1那么相当于select top 1...
--在set rowcount以后一般是把这个设置为0免得对下面有影响
usun82 2009-10-20
  • 打赏
  • 举报
回复
太帅了 !!!
真是这样,我昨天搞了半下午,晚上想了一晚都没搞出来,set rowcount @endIndex
这个是什么原因啊?
usun82 2009-10-20
  • 打赏
  • 举报
回复
这个存储过程是参考你昨天给我写的写出来的,一开始没有问题,后来不知道休息了什么地方,就出现了这个奇怪的问题,为什么单独用select * from RE_NewsColumn_NewsTopics 查结果有3条记录,一把这个存储过程剪贴到这个查询分析器下,再用select * from RE_NewsColumn_NewsTopics 查结果就只能查到一条记录呢,实在不明白。。。。
bancxc 2009-10-20
  • 打赏
  • 举报
回复
o
[Quote=引用 2 楼 js_szy 的回复:]
粗略的看来一下。可能跟这个有关系


set rowcount @endIndex
[/Quote]
华夏小卒 2009-10-20
  • 打赏
  • 举报
回复
粗略的看来一下。可能跟这个有关系


set rowcount @endIndex
--小F-- 2009-10-20
  • 打赏
  • 举报
回复
没见过 仔细检查存储过程

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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