[dba-SQLServer] Strange happening

jwcolby jwcolby at colbyconsulting.com
Wed Feb 27 17:46:33 CST 2008


I have a pretty strange happening. 

I have a table with a PK which is an autoincrement int.  When I create a
view and include that field, then all order by clauses are ignored.  IOW I
create a query 

SELECT PKID, Fld1, fld2, fld3 ORDER By Fld3 DESC

And when executed the data is ordered by PKID.

If I save the view and then create a QUERY SELECT * from MyView ORDER BY
Fld3 DESC then it does in fact order by fld3 desc order.  If I save THAT SQL
MSTATEMENT into another view and then execute that view, I am right back to
ordered by PKID.

I am at a loss as to why this happens and how to avoid it.  I am trying to
pull the first 1 million rows, ordered in a random order (for testing of
another app) so I tried creating a view where I order by zip 4 DESC.  I
store the view and then export the view into a CSV file.  The data comes out
ordered on the PKID.

Truly weird!

I can't go further on my testing until I get this resolved.

John W. Colby
Colby Consulting
www.ColbyConsulting.com 




More information about the dba-SQLServer mailing list