简体   繁体   English

为什么我收到 Microsoft SQL:Power BI 上的语法错误?

[英]Why I am getting Microsoft SQL: Incorrect syntax error on Power BI?

I am trying to get some data using CTE, but it gives me an error that I have to use semicolons.我正在尝试使用 CTE 获取一些数据,但它给了我一个错误,我必须使用分号。 I think I fixed that by putting ;我想我通过放置来解决这个问题; in front of WITH, but now I am getting Microsoft SQL: Incorrect syntax near ';'. Incorrect syntax near ')'.在 WITH 前面,但现在我得到了Microsoft SQL: Incorrect syntax near ';'. Incorrect syntax near ')'. Microsoft SQL: Incorrect syntax near ';'. Incorrect syntax near ')'.

Can anybody please tell me what is wrong?谁能告诉我出了什么问题? It used to be very easy, just copy the query from MS SQL to Power BI.过去很简单,只需将查询从 MS SQL 复制到 Power BI。 My query runs fine in MS SQL.我的查询在 MS SQL 中运行良好。

;WITH unit AS (
   SELECT
         tm.create_date 
       , tm.timeslip_date
       , cases.case_sk
       , cases.case_number
       , cases.closed_ind
       , cases.atty2_sk
       , vc.atty2_name    AS [Business Leader]
       , em.smtp_reply_to AS [Business Leader Email]
       , cases.atty1_sk
       , vc.atty1_name    AS [Assign Attorney]
       , tm.detail_notes
   FROM dbo.cases
   LEFT JOIN dbo.vcases vc ON cases.case_sk = vc.case_sk
   LEFT JOIN dbo.employee em ON cases.atty2_sk = em.employee_sk    
   LEFT JOIN dbo.timeslips tm ON cases.case_sk = tm.case_sk
   WHERE cases.closed_ind = 'O'
   AND NOT EXISTS(SELECT * FROM dbo.timeslips tsm WHERE tsm.case_sk = cases.case_sk AND tsm.timeslip_date > DATEADD(day, -90, GETDATE()) )
), agg AS (
   SELECT
         MIN(u.create_date)   AS [Created Date]
       , MAX(u.timeslip_date) AS [Last Bill Date]
       , u.case_sk
       , u.case_number
       , u.closed_ind
       , u.atty2_sk
       , u.[Business Leader]
       , u.[Business Leader Email]
       , u.atty1_sk
       , u.[Assign Attorney]
   FROM unit u
   GROUP BY 
         u.case_sk
       , u.case_number
       , u.closed_ind
       , u.atty2_sk
       , u.[Business Leader]
       , u.[Business Leader Email]
       , u.atty1_sk
       , u.[Assign Attorney]
)
SELECT agg.*, unit.detail_notes
FROM agg
INNER JOIN unit
   ON  agg.[Last Bill Date] = unit.[timeslip_date]
        AND agg.case_sk = unit.case_sk
        AND agg.case_number = unit.case_number
        AND agg.closed_ind = unit.closed_ind
        AND agg.atty2_sk = unit.atty2_sk
        AND agg.atty1_sk = unit.atty1_sk

Thank you谢谢

When you use a custom query as a DirectQuery source you must supply a query that PowerBI can compose additional critera and joins on at runtime.当你使用自定义查询作为 DirectQuery 源时,你必须提供一个查询,PowerBI 可以在运行时组成额外的条件和联接。

If you create a DirectQuery source with a query like this如果您使用这样的查询创建 DirectQuery 源

with q as (select * from sys.objects) select * from q

PowerBI will compose queries like PowerBI 将编写查询,如

select * from (
    with q as (select * from sys.objects) select * from q
) SourceQuery where 1 = 2

The error you get has nothing to do with whether you have a statement terminator or not.你得到的错误与你是否有语句终止符无关。 ; is not allowed in the middle of a query, but nether is with .在查询中是不允许的,但幽冥是with CTE's are great but they have a flaw: they are not "composable". CTE 很棒,但它们有一个缺陷:它们不是“可组合的”。

You can work around this by installing the query as a view in SQL Server, or transforming the CTE subqueries into nested subqueries, but that query is really much too complicated to be used in a DirectQuery model.您可以通过将查询安装为 SQL Server 中的视图或将 CTE 子查询转换为嵌套子查询来解决此问题,但该查询实在太复杂而无法在 DirectQuery 模型中使用。 So you'd really need to load the results into a table to use DirectQuery, or switch to Import and run the query only on refresh.因此,您确实需要将结果加载到表中以使用 DirectQuery,或者切换到导入并仅在刷新时运行查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM