ORDER BY子句在视图,内联函数中无效, [英] ORDER BY clause is invalid in views, inline functions,

查看:411
本文介绍了ORDER BY子句在视图,内联函数中无效,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的查询



This one is my query

select distinct top(8)  sumit.CouponsID, sumit.Items_Desc_ThumbImageURl, sumit.CouponsShopCity,
sumit.Items_Desc_UpdatedON, sumit.Prod_Cat_Name,sumit.Prod_Sub_Cat_Name,
sumit.CouponsEndDate
from
(
select ROW_NUMBER() over(PARTITION BY  CouponsStock.CouponsShopCity
order by CouponsStock.CouponsShopCity desc)
as rowno,
CouponsStock.CouponsID,
CouponsStock.CouponsEndDate,
ProductCategory.Prod_Cat_Name, ProductSubCategory.Prod_Sub_Cat_Name,
CouponsStock.CouponsShopCity,
ProdSubCatItemsDescription.Items_Desc_UpdatedON ,
ProdSubCatItemsDescription.Items_Desc_ThumbImageURl
from ProductCategory inner join ProductSubCategory
on ProductCategory.Prod_Cat_ID=ProductSubCategory.Prod_Cat_ID
inner join ProductSubCatItmes on
ProductSubCategory.Prod_Sub_Cat_ID=ProductSubCatItmes.Prod_Sub_Cat_ID
inner join ProdSubCatItemsDescription  on
ProductSubCatItmes.Prod_Sub_Cat_Items_ID=ProdSubCatItemsDescription.Prod_Sub_Cat_Items_ID
inner join CouponsStock on
ProdSubCatItemsDescription.Prod_Sub_Cat_Items_Desc_ID=CouponsStock.Prod_Sub_Cat_Items_Desc_ID
where  CouponsStock.CouponsStatus='visible' and
CouponsStock.CouponsEndDate>=GETDATE() order by CouponsStock.CouponsEndDate desc
)
as sumit where sumit.rowno=1
order by sumit.Items_Desc_UpdatedON







之后执行Above查询....它抛出以下错误..




After Executing Above query....it''s throw following error..

Msg 1033, Level 15, State 1, Line 25
The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified.





任何人都可以指导我如何执行以上查询............



Can any one guide me how can i execute above query............

推荐答案

在视图 ORDER BY 。 com / 2010/08/23 / sql-server-order-by-does-not-work-limitation-of-views-part-1 /> [ ^ ]。因此,从视图中删除 ORDER BY 以修复错误。
You cannot have an ORDER BY inside a view[^]. Thus remove the ORDER BY from the view to fix the error.


这篇关于ORDER BY子句在视图,内联函数中无效,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆