| Author |
Topic |
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2007-06-10 : 04:48:36
|
Hi All, I hope all of you are doing good. !!Well, this is one of the issue which i came accross while migration from SQL SERVER 2000 to SQL SERVER 2005. The query perform differently in 2000 and 2005. PS: This is just an Test Data and not the Real SQL SERVER 2000Declare @a Table ( i varchar(10), k int)Insert @aSelect 'a', 1 Union All Select 'h', 3 Union All Select 'j', 4 Union All Select 'l', 2 Union All Select 'g', 5 -- FIRST QUERY Select * From @a order by k -- SECOND QUERY Select * From ( Select Top 100 Percent * From @a order by k ) as f --OUTPUT i k---------- -----------a 1l 2h 3j 4g 5i k---------- -----------a 1l 2h 3j 4g 5 SQL SERVER 2005Declare @a Table ( i varchar(10), k int)Insert @aSelect 'a', 1 Union All Select 'h', 3 Union All Select 'j', 4 Union All Select 'l', 2 Union All Select 'g', 5 -- FIRST QUERY Select * From @a order by k -- SECOND QUERY Select * From ( Select Top 100 Percent * From @a order by k ) as f --OUTPUT i k---------- -----------a 1l 2h 3j 4g 5i k---------- -----------a 1h 3j 4l 2g 5 I solved in the thing in the query.. but was just wondering is this a new thing or know???Chiraghttp://chirikworld.blogspot.com/ |
|
|
Kristen
Test
22859 Posts |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2007-06-10 : 09:15:31
|
| aha.. Thanks Kristen for the pointer..!!Chiraghttp://chirikworld.blogspot.com/ |
 |
|
|
LoztInSpace
Aged Yak Warrior
940 Posts |
Posted - 2007-06-11 : 00:33:41
|
| Waht a shame TOP 100 PERCENT is still legal syntax when used like this. I'm not sure which is worse after an upgrade - breaking loads of 'working' code & views or having them still execute but return different results to before.Out of interest, what do you want an order by in a sub-select anyway? Why not just do it on the outside? My guess is some internal framework perhaps? |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-06-11 : 03:42:58
|
| "I'm not sure which is worse after an upgrade - breaking loads of 'working' code & views or having them still execute but return different results to before"Well I take a different view! I can't imagine putting "TOP 100 PERCENT" in my code as it so obviously reads like a kludge ..."Out of interest, what do you want an order by in a sub-select anyway"There you go then - you agree too!!Kristen |
 |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2007-06-11 : 04:14:26
|
quote: Out of interest, what do you want an order by in a sub-select anyway? Why not just do it on the outside? My guess is some internal framework perhaps?
Well it was a view which was coded 5 years back.. and was working wonderfully without this upgrade... .. And its functionality was just to bind to one of grid and then user uses to extract this to excel .... Chiraghttp://chirikworld.blogspot.com/ |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-06-11 : 06:04:31
|
Shouldn't code Order Dependency in a VIEW - any more than you can't do that in a Table either !!But-I-know-that-you-know-that !!Pain to sort out, none the less, but think of it like moving house and clearing out all the crud (CRUD? ) in the attic!Kristen |
 |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2007-06-11 : 06:45:38
|
Pain to sort out, none the less, but think of it like moving house and clearing out all the crud (CRUD? ) in the attic!Aha.. thatz the good way to pump in the Enthusiams.. for rework  Chiraghttp://chirikworld.blogspot.com/ |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-06-11 : 07:45:38
|
| Nah, its Refactoring ... you can charge more for that! |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-06-11 : 09:27:15
|
| can Anyone give any example how order by in a subquery matters?MadhivananFailing to plan is Planning to fail |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-06-11 : 10:25:00
|
"can Anyone give any example how order by in a subquery matters?"CREATE VIEW VAS( SELECT TOP 100 PERCENT * FROM MyTable ORDER BY MyColumn DESC) but it is Crap Code to start with of course ... ... and it isn't strictly a Sub Query ... Kristen |
 |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2007-06-12 : 07:43:06
|
Nah, its Refactoring ... you can charge more for that!Company provides as an complementary.. so cant charge Chiraghttp://chirikworld.blogspot.com/ |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-06-12 : 07:57:03
|
| order in subquery is completly irrelevant so top 100 percent is also irrelevant._______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenp |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-06-12 : 09:11:33
|
| I still dont understand why order by in subquery is allowedMadhivananFailing to plan is Planning to fail |
 |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2007-06-12 : 09:17:35
|
| order in subquery is completly irrelevant so top 100 percent is also irrelevant.Agreed !!! I still dont understand why order by in subquery is allowedMay be just for backward compatiblity, with 2000.. Chiraghttp://chirikworld.blogspot.com/ |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-06-12 : 10:04:29
|
| it should be allowed exactly because of top clause.and also top 100 percent is rightfully disregarded in parsing._______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenp |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-06-12 : 12:24:45
|
| hehehe .. so it HAS provided the TOP 100 Percent of the sub-query .... just there is no Side Effect of ordering the data. Seems OK to me ... |
 |
|
|
|