查看订单消失 [英] View Order Dissappearing
问题描述
当我在SQL中创建一个视图并包含一个ORDER BY子句时,我可以在Management Studio中看到它是
。但是,当我从ASP
页面调用相同的视图时,订单完全失控。
任何想法?
Hurricane写道:
当我在SQL中创建一个视图并包含一个ORDER BY子句时,我可以看到它
。但是,当我从ASP
页面调用相同的视图时,订单完全失控。
有什么想法吗?
根据定义,视图是无序的。 ORDER BY在视图中非常有用
定义要由TOP子句选择的行子集 - 它不会影响查询的预期排序反对视图。
正确的方法是将ORDER BY添加到SELECT语句中,
查询视图。
-
David Portas,SQL Server MVP
请尽可能发布足够的代码来重现您的问题。
包含CREATE TABLE和INSERT语句通常会有所帮助。
说明您正在使用的SQL Server版本,并指定任何错误消息的内容
。
SQL Server联机丛书:
http://msdn2.microsoft.com/library/m...S,SQL.90).aspx
-
Hurricane写道:
当我创建一个视图时在SQL中包含一个ORDER BY子句,我可以在Management Studio中看到它是
。但是,当我从ASP
页面调用相同的视图时,订单完全失控。
好!视图没有被调用,它们是从中选择的。
当你发出一个SELECT它只有一个ORDER,如果你指定它
SELECT。
视图定义中指定的任何顺序都是无关紧要的。只有TOP
关心嵌套订单
干杯
Serge
-
Serge Rielau
DB2解决方案开发
IBM多伦多实验室
WAIUG会议
http://www.iiug.org/waiug/present/Fo ... Forum2006.html
" Hurricane" < mg ******* @ gmail.com写信息
新闻:11 ********************** @ t46g2000cwa.googlegr oups.com ...
当我在SQL中创建一个视图并包含一个ORDER BY子句时,我可以看到它
在Management Studio中。但是,当我从ASP
页面调用相同的视图时,订单完全失控。
任何想法?
您的视图是否指定前100%?
创建视图dbo.OrderByDateView
AS
SELECT TOP 100 PERCENT Field1,Field2,Date1
FROM Table1
ORDER BY Date1
When I create a view in SQL and include an ORDER BY clause i can see it
in Management Studio. However, when I call the same view from an ASP
page the order goes completely haywire.
Any ideas?
Hurricane wrote:When I create a view in SQL and include an ORDER BY clause i can see it
in Management Studio. However, when I call the same view from an ASP
page the order goes completely haywire.
Any ideas?
Views are unordered by definition. ORDER BY is useful in a view only to
define the subset of rows to be selected by the TOP clause - it doesn''t
affect the expected ordering of a query against the view.
The right way to do it is to add ORDER BY to the SELECT statement that
queries the view.
--
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/m...S,SQL.90).aspx
--
Hurricane wrote:When I create a view in SQL and include an ORDER BY clause i can see it
in Management Studio. However, when I call the same view from an ASP
page the order goes completely haywire.Good! views aren''t called, they are selected from.
When you issue a SELECT it only has an ORDER if you specify it for that
SELECT.
Any order specified inside the view definition is irrelevant. Only TOP
cares for nested ORDERs
Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
WAIUG Conference
http://www.iiug.org/waiug/present/Fo...Forum2006.html
"Hurricane" <mg*******@gmail.comwrote in message
news:11**********************@t46g2000cwa.googlegr oups.com...When I create a view in SQL and include an ORDER BY clause i can see it
in Management Studio. However, when I call the same view from an ASP
page the order goes completely haywire.
Any ideas?
Does your view specify TOP 100 PERCENT?
CREATE VIEW dbo.OrderByDateView
AS
SELECT TOP 100 PERCENT Field1, Field2, Date1
FROM Table1
ORDER BY Date1
这篇关于查看订单消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!