注册 登录
编程论坛 SQL Server论坛

[求助]在另一个编程论坛中发现的一个问题,想咨询一下大家!

paul3292 发布于 2007-03-23 09:12, 663 次点击

user pubs
go
1.
declare @str varchar(1000)
set @str = ''
select @str = @str + fname + ' - ' from employee where job_id = 5
order by hire_date
print @str

2.
declare @str varchar(1000)
set @str = ''
select @str = @str + fname + ' - ' from employee where job_id = 5
--order by hire_date
print @str

3.
declare @str varchar(1000)
set @str = ''
select @str = @str + fname + ' - ' from (select top 99 percent * from employee where job_id = 5 order by hire_date) b
print @str

4.
declare @str varchar(1000)
set @str = ''
select @str = @str + fname + ' - ' from (select top 100 percent * from employee where job_id = 5 order by hire_date) b
print @str

查询结果很令我吃惊,想知道为什么,谢谢

8 回复
#2
棉花糖ONE2007-03-23 09:23

你的电脑打过补丁没,应该是sql server的一个bug,以前就看到有人在操作自带的数据库的时候出现奇怪问题.我模拟了一下没出现那奇怪现象
if object_id('student') is not null
drop table student
go
create table student(id int,name varchar(20))
insert into student select 1,'aa'
insert into student select 1,'bb'

declare @str varchar(100)
select @str=''
select @str=@str+name+'-' from student where id=1
print @str

declare @str varchar(100)
select @str=''
select @str=@str+name+'-' from student where id=1 order by id
print @str

declare @str varchar(100)
select @str=''
select @str=@str+name+'-' from (select top 50 percent name from student where id=1 order by id desc) s
print @str

declare @str varchar(100)
select @str=''
select @str=@str+name+'-' from (select top 100 percent name from student where id=1 order by id desc) s
print @str

#3
Kendy1234562007-03-23 11:03
完全没看明白。。。什么bug 什么吃惊。。。
#4
棉花糖ONE2007-03-23 11:11
晕,你自己去运行下看看
#5
paul32922007-03-23 14:43
哦了,我试试,这两天重装的系统,应该是补丁的问题!
#6
棉花糖ONE2007-03-23 22:56
打sp4就不出现那问题
#7
xiyou4192007-03-24 18:18
我的也是,有问题,要打补丁了!!
#8
初学Delphi2007-03-26 13:30
第一个的原因我觉的像那个经典查询例子里似的(列变行的那个)
#9
棉花糖ONE2007-03-26 13:36

不是的.我打上补丁就没问题了

1