sql2000的bug?

cxmcxm 2010-10-09 10:37:54
加精
实际应用中偶然发现,@@version为8.0.194

declare @tmp table (id1 int identity(1,1),id int,nid int,fday int,fexp nvarchar(50))
--nid为用于最后排序输出,fday为日期,先插入各天业务,再计算各天发生额与余额,再计算月发生额与余额
--最后按日期排序输出。
declare @tmp1 table (id int)
insert into @tmp (id,nid,fday,fexp)
select 1,0,1,'业务'
union all select 1,0,1,'业务' union all select 1,0,1,'业务'
union all select 1,0,2,'业务' union all select 1,0,2,'业务'
union all select 1,0,2,'业务' union all select 1,0,2,'业务'
union all select 1,0,3,'业务' union all select 1,0,3,'业务'
union all select 1,0,5,'业务' union all select 1,0,5,'业务'
union all select 1,0,5,'业务' union all select 1,0,8,'业务'
union all select 1,0,8,'业务' union all select 1,0,8,'业务'
union all select 1,0,8,'业务' union all select 1,0,9,'业务'
union all select 1,0,9,'业务' union all select 1,0,10,'业务'
union all select 1,0,10,'业务' union all select 1,0,10,'业务'
union all select 1,0,11,'业务' union all select 1,0,12,'业务'
union all select 1,0,12,'业务' union all select 1,0,12,'业务'
union all select 1,1,1,'本日发生额与余额' union all select 1,1,2,'本日发生额与余额'
union all select 1,1,3,'本日发生额与余额' union all select 1,1,5,'本日发生额与余额'
union all select 1,1,8,'本日发生额与余额' union all select 1,1,9,'本日发生额与余额'
union all select 1,1,10,'本日发生额与余额' union all select 1,1,11,'本日发生额与余额'
union all select 1,1,12,'本日发生额与余额' union all select 1,2,31,'本月发生额与余额'
insert into @tmp1 values (1)

select a.id,a.id1,count(*) nid
from @tmp a,@tmp b,@tmp1 c
where a.id=b.id and a.id=c.id and (a.fday>b.fday or a.fday=b.fday and a.nid>b.nid or a.fday=b.fday and a.nid=b.nid and a.id1>=b.id1)
group by a.id,a.id1
order by 1,3

update aa
set nid=bb.nid
from @tmp aa,
( select a.id,a.id1,count(*) nid
from @tmp a,@tmp b,@tmp1 c
where a.id=b.id and a.id=c.id and (a.fday>b.fday or a.fday=b.fday and a.nid>b.nid or a.fday=b.fday and a.nid=b.nid and a.id1>=b.id1)
group by a.id,a.id1) bb
where aa.id=bb.id and aa.id1=bb.id1
--update后输出结果不正确,nid不是子查询的连续整数。
select * from @tmp order by id,nid

结果

id id1 nid
----------- ----------- -----------
1 1 1
1 2 2
1 3 3
1 26 4
1 4 5
1 5 6
1 6 7
1 7 8
1 27 9
1 8 10
1 9 11
1 28 12
1 10 13
1 11 14
1 12 15
1 29 16
1 13 17
1 14 18
1 15 19
1 16 20
1 30 21
1 17 22
1 18 23
1 31 24
1 19 25
1 20 26
1 21 27
1 32 28
1 22 29
1 33 30
1 23 31
1 24 32
1 25 33
1 34 34
1 35 35

(35 行受影响)

(35 行受影响)

id1 id nid fday fexp
----------- ----------- ----------- ----------- --------------------------------------------------
1 1 1 1 业务
2 1 2 1 业务
3 1 2 1 业务
26 1 2 1 本日发生额与余额
27 1 5 2 本日发生额与余额
4 1 5 2 业务
5 1 5 2 业务
6 1 5 2 业务
7 1 5 2 业务
8 1 10 3 业务
9 1 10 3 业务
28 1 10 3 本日发生额与余额
29 1 13 5 本日发生额与余额
10 1 13 5 业务
11 1 13 5 业务
12 1 13 5 业务
13 1 17 8 业务
14 1 17 8 业务
15 1 17 8 业务
16 1 17 8 业务
30 1 17 8 本日发生额与余额
31 1 22 9 本日发生额与余额
17 1 22 9 业务
18 1 22 9 业务
19 1 25 10 业务
20 1 25 10 业务
21 1 25 10 业务
32 1 25 10 本日发生额与余额
22 1 29 11 业务
33 1 29 11 本日发生额与余额
34 1 31 12 本日发生额与余额
23 1 31 12 业务
24 1 31 12 业务
25 1 31 12 业务
35 1 35 31 本月发生额与余额

(35 行受影响)


如果改为表,则正常,在sql2005中测试也正常,未安装2000sp4,希望安装sp4的帮助测试是否正常
...全文
956 105 打赏 收藏 转发到动态 举报
写回复
用AI写文章
105 条回复
切换为时间正序
请发表友善的回复…
发表回复
pandeyy 2010-10-15
  • 打赏
  • 举报
回复
学习了
dawugui 2010-10-15
  • 打赏
  • 举报
回复
[Quote=引用 93 楼 cxmcxm 的回复:]
发此贴主要是将发现的2000bug公布与大家知,语句的逻辑无问题的。and 的优先级>or,加不加括号无所谓,加了括号,可读性会好一些。[/Quote]

当你以后知道加()的重要性的时候,你可能才知道我说的那句话也许值60万.

这个60万值得国人深思啊?
Sevn531897917 2010-10-15
  • 打赏
  • 举报
回复
顶啊!
fengyun142415 2010-10-14
  • 打赏
  • 举报
回复
学习一下
yangtututu 2010-10-14
  • 打赏
  • 举报
回复
回帖 10分
louisit 2010-10-14
  • 打赏
  • 举报
回复
学习.
yu_310 2010-10-14
  • 打赏
  • 举报
回复
现在用的有点少
  • 打赏
  • 举报
回复
测试结果跟楼主一样。
PS:原来SQL 2000的查询分析器可以连接到SQL 2005服务器。

hovy_yang 2010-10-14
  • 打赏
  • 举报
回复
学习
阿布Guu 2010-10-14
  • 打赏
  • 举报
回复
sql 还没有 2009 、 2010 呢
xmp250 2010-10-14
  • 打赏
  • 举报
回复
2008也不见的就完全比2000好.现在朋友中用2000的比2005感觉舒服多的大有人在.更别说2009,2010
cxmcxm 2010-10-13
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 sqlcenter 的回复:]
引用 5 楼 dawugui 的回复:

你这里写得不对吧?
a.fday>b.fday or a.fday=b.fday and a.nid>b.nid or a.fday=b.fday and a.nid=b.nid and a.id1>=b.id1

-->

a.fday>b.fday or (a.fday=b.fday and a.nid>b.nid) or (a.fday……
[/Quote]
发此贴主要是将发现的2000bug公布与大家知,语句的逻辑无问题的。and 的优先级>or,加不加括号无所谓,加了括号,可读性会好一些。
cxmcxm 2010-10-13
  • 打赏
  • 举报
回复
[Quote=引用 82 楼 sqlcenter 的回复:]
引用 75 楼 renzhe02 的回复:

引用 5 楼 dawugui 的回复:
你这里写得不对吧?
a.fday>b.fday or a.fday=b.fday and a.nid>b.nid or a.fday=b.fday and a.nid=b.nid and a.id1>=b.id1

-->
……
我这2000 sp3补丁,两个测试条件的结果都是一致的,结果也对!
……
[/Quote]
问题是在开发过程中偶然发现的,sp3如果是无问题,证明bug已修改好。
找一张原始sql2000安装盘安装,或者安装盘中的msde2000,试一试就清楚了。
原始版为2000.194
angel_reachel 2010-10-13
  • 打赏
  • 举报
回复
不懂~~
feng_family 2010-10-13
  • 打赏
  • 举报
回复
才接触没多久
fengyun142415 2010-10-13
  • 打赏
  • 举报
回复
学习一下!
q107770540 2010-10-13
  • 打赏
  • 举报
回复
debugisgood 2010-10-13
  • 打赏
  • 举报
回复
路过.............................................................
DKCCR 2010-10-13
  • 打赏
  • 举报
回复
SQL2000版本的呀!我彻底崩溃了!我现在都用自动化2008的咯!
我看着那么多代码我都晕了!不过支持!加油调试哦
l2008l 2010-10-13
  • 打赏
  • 举报
回复
看不懂 纯粹来学习的
加载更多回复(68)

34,594

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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