Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
jirpun
Starting Member
2 Posts |
Posted - 2010-02-02 : 08:32:23
|
Hi all,I have registered a differ behavior between the SQL server 2000 and 2008.The next sample below returns different results, the rows are differently numbered.In the SQL server 2008:id_test_table some_code------------- ---------0 A1 B2 C3 D4 Ein the SQL server 2000:id_test_table some_code ------------- --------- 1 A2 B3 C4 D5 EDoes anybody know a reason, an explanation?Thanks to all.Jiri create function dbo.TheSameInt(@pInt int)returns intasbegin return @pIntend go create table #test_table( id_test_table INT, some_code CHAR(1))go insert into #test_table values (0, 'A')insert into #test_table values (0, 'B')insert into #test_table values (0, 'C')insert into #test_table values (0, 'D')insert into #test_table values (0, 'E')godeclare @v_counter intset @v_counter = 0update #test_table set id_test_table = dbo.TheSameInt(@v_counter), @v_counter = @v_counter + 1select * from #test_table drop table #test_table go |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-02-02 : 08:54:41
|
| It is a behavioural change from one version to another versionIn version 2000, variable is calculated and used no matter which order it is. But in version 2005 onwards the order is forced. So your code should bedeclare @v_counter intset @v_counter = 0update #test_table set @v_counter = @v_counter + 1,id_test_table = dbo.TheSameInt(@v_counter)select * from #test_table MadhivananFailing to plan is Planning to fail |
 |
|
|
jirpun
Starting Member
2 Posts |
Posted - 2010-02-02 : 09:13:43
|
quote: Originally posted by madhivanan It is a behavioural change from one version to another versionIn version 2000, variable is calculated and used no matter which order it is.
Ok, the solution is clear.But is this behavioural change documented anywhere?Jiri |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|
|
|