sql查询的奇怪问题????
真是服了,昨天写了个存储过程,遇到了一个奇怪的问题
我用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
涉及到的表的脚本太长,如果大家测试我把表的脚本也发上来,谢谢帮忙解决!!!
我用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
涉及到的表的脚本太长,如果大家测试我把表的脚本也发上来,谢谢帮忙解决!!!
...全文
相关推荐
SQL Server上的一个奇怪的Deadlock及其分析方法
SQL Server上的一个奇怪的Deadlock及其分析方法Deadlock是SQL Server中的一种常见问题,它会导致事务无法继续执行,影响系统的性能和可靠性。
解决在SQL脚本中的注释引起的奇怪问题
然而,有时候在SQL脚本中添加注释可能会引发一些意外的问题,特别是在使用osql.exe工具时可能会遇到一些不直观的错误提示。
奇怪的SQL_可以进一步跟进.
一个奇怪的sql.运行环境:vs2013的工具"connect to database"下的query window.效果:空白字符导致查询条件无效. 需要使用抓包工具进一步分析.
T-SQL查询逻辑谜题[归类].pdf
"T-SQL查询逻辑谜题[归类]"本资源提供了一系列逻辑谜题,旨在提高解决SQL问题的能力。
SQL Server 2008:如何面对众多选择?——复杂的版本问题和令人困惑的许可选项令SQL Server备受挫折.pdf
利用社区论坛寻找解决方案:SQL Server Magazine论坛等社区资源为用户提供了一个交流的平台,专家们在这里分享他们的经验,讨论如何解决棘手的问题以及一些奇怪的“bug”。


疑难问题
