我尝试了此查询,但出现以下错误。我只使用select查询。我不明白为什么不能使用此查询创建视图。
order by子句在视图、内联函数、派生表、子查询和公共表表达式中无效,除非还指定了top、offset或for xml。
查询
CREATE VIEW [dbo].[BF_Product_Categories] AS
SELECT
*
FROM
(
SELECT
30 AS ProductCategoryID,
'All Apps' AS ProductCategory,
'All Apps' AS Description,
'AA' AS Sort,
NULL AS ProductSubCategory,
NULL AS ProductSubCategoryID
UNION ALL
SELECT
TOP (100) dbo.bf_productcategories.productcategoryid,
dbo.bf_productcategories.productcategory,
dbo.bf_productcategories.description,
dbo.bf_productcategories.sort,
dbo.bf_productsubcategories.productsubcategory,
dbo.bf_productsubcategories.productsubcategoryid
FROM
dbo.bf_productcategories
LEFT OUTER JOIN dbo.bf_productsubcategories ON dbo.bf_productcategories.productcategoryid = dbo.bf_productsubcategories.productcategoryid
WHERE
(
dbo.bf_productcategories.status = 'True'
)
AND (
Isnull (
(
SELECT
Count(
productcategory_subcategorymapid
) AS Expr1
FROM
dbo.bf_productcategory_subcategorymaps AS A
WHERE
(
productcategoryid = dbo.bf_productcategories.productcategoryid
)
),
0
) <> 0
)
) AS AllProductCategories
ORDER BY
sort
我在stackoverflow上发现了有关此错误的问题,并尝试了一些答案,但无法解决它。我真的需要帮助。
暂无答案!
目前还没有任何答案,快来回答吧!