CTE 在 SSAS 导入模式下工作,但在 SSAS 直接查询模式下不工作

CTE is working in SSAS Import mode but is not working in SSAS Direct Query mode

提问人:Vickar 提问时间:11/8/2023 最后编辑:Vickar 更新时间:11/8/2023 访问量:45

问:

我正在使用包含 CTE 的本机查询在 SSAS 中创建表。当我在 IMPORT 模式下将 CTE 用于 SSAS 模型时,它运行良好。但是,当我在 DIRECT QUERY 模式下在 SSAS 模型中使用相同的 CTE 时,我能够在 SQL Server 上部署该模型,但是当我尝试从 SSMS 或 DAX Studio 查询数据时,出现如下错误

正在执行查询...OLE DB 或 ODBC 错误:[DataSource.Error] Microsoft SQL:关键字“with”附近的语法不正确。关键字“with”附近的语法不正确。如果此语句是公用表表达式、xmlnamespaces 子句或更改跟踪上下文子句,则必须用分号终止上一个语句。“)”附近的语法不正确。运行完成

有人可以帮我了解 SSAS DIRECT QUERY 模式是否不支持 CTE 吗?我在网上找不到任何相关信息。

    ;with crmhfCTE as (
SELECT     
    lp.d_Book_Date as Transaction_Date
    ,hfa.OfferSelectedBase as Funding_Amount
    ,hfa.RealEstateActualPrice as Funded_Asset_Purchase_Amount
    ,N'شراء جاهز' as Product_type  
    ,hfa.PropertyType as Property_Type_Code
    ,(select lookupvalue  from CRM_Lookups  as lup where 1=1 and hfa.PropertyType = lup.lookupcode and  LookupType = 'vrp_propertytype' )  as Property_Type_Name
    ,hfa.SellerName as Seller_Data
    ,hfa.CustomerName as Customer_Name
    ,'750' as VAT_Amount
    ,hfa.ApplicationID as Transaction_Number
    ,hfa.FirstTimeHouseBuyer as First_Time_House_Buyer_Flag
    ,'-' as Annual_Statement_Of_Sold_Debts
    ,lp.v_type as Loan_Type
    ,lp.d_Extraction_Date as Extraction_Date
FROM HF_Application as hfa
RIGHT JOIN(
    SELECT 
        v_Application_Num
        ,d_Book_Date
        ,v_Type 
        ,d_Extraction_Date
    FROM Retail_Loan_Contract_Hist
        WHERE 1=1
        and v_Type IN ('RCMF')
) as lp on hfa.ApplicationID = lp.v_Application_Num

where 1=1 
and hfa.IsCurrent = 'y'

)

select 
    Transaction_Date as 'Transaction Date'
    ,Funding_Amount as 'Funding Amount'
    ,Funded_Asset_Purchase_Amount as 'Funded Asset Purchase Amount'
    ,Product_type  as 'Product Type'
    ,case Property_Type_Name
        when 'Ready Built Duplex' then N'دبلكس'
        when 'Ready Built Villa' then N'فيلا'
        when 'Ready Built Apartment' then N'شقة'
        when 'Ready Built Building' then N'مبنى'
        else Property_Type_Name  end as  'Property Type Name Arabic'
    ,Seller_Data as 'Seller Data'
    ,Customer_Name as 'Customer Name'
    ,VAT_Amount as 'VAT Amount'
    ,Transaction_Number as 'Transaction Number'
    ,First_Time_House_Buyer_Flag as 'First Time House Buyer Flag'
    ,Annual_Statement_Of_Sold_Debts as 'Annual Statement Of Sold Debts'
    ,Loan_Type as 'Loan Type'
    ,Extraction_Date as 'Extraction Date'
from crmhfCTE
sql-server reporting-services powerbi ssas ssas-tabular

评论

1赞 Dale K 11/8/2023
您需要显示查询。我假设任何以前的语句都是以分号结尾的?
0赞 Vickar 11/8/2023
我已经用查询更新了我的问题
1赞 mxix 11/8/2023
移除 CTE。只需执行子查询,或使用代码创建视图并指向该视图,这要灵活得多,因为无需重新部署 SSAS 解决方案即可更改视图

答:

0赞 Vickar 11/8/2023 #1

正如 mxix 在问题注释中建议的那样,创建包含 CTE 代码的视图,然后在 Direct Query 模式下在 SSAS 中访问此视图对我有用。