簡體   English   中英

嘗試在 SAP 的信息設計工具中運行查詢(使用 mssql 數據庫)

[英]Trying to run a query in Information Design Tool in SAP (using mssql database)

WITH c   AS
    (SELECT A.QuestionHdrKey AS QuestionHdrKey1,
            A.DivisionKey AS DivisionKey1,
            COUNT(1) AS QCount
     FROM Mobile.QuestionLocationMap A WITH (NOLOCK)
          INNER JOIN Mobile.Question b WITH (NOLOCK) ON A.QuestionKey = b.PKey
     WHERE A.QuestionHdrKey = 200305685377000000
     GROUP BY A.QuestionHdrKey,
              A.DivisionKey),
d   AS
    (SELECT a.QuestionHdrKey,
            a.QuestionKey,
            a.DivisionKey,
            a.InvDate,
            a.HdrKey,
            ROW_NUMBER() OVER (PARTITION BY a.DivisionKey,
                                            a.invdate,
                                            a.HdrKey
                               ORDER BY a.QuestionKey) AS RowId
     FROM mobile.StatusReport a WITH (NOLOCK)
          INNER JOIN mobile.Question b WITH (NOLOCK) ON a.QuestionKey = b.PKey
                                                    AND b.QuestionType = 'rate'
                                                    AND InputType = 'numeric'
     WHERE a.QuestionHdrKey = '200305685377000000'
     GROUP BY a.QuestionHdrKey,
              a.DivisionKey,
              a.HdrKey,
              a.InvDate,
              a.QuestionKey)
SELECT a.DivisionKey,
       a.InvDate AS ModifiedDate,
       a.QuestionHdrKey,
       a.HdrKey,
       COUNT(DISTINCT a.QuestionKey) AS QuestionKey,
       SUM(CAST(a.Value AS int)) AS value,
       SUM(b.Rate) AS RATE
--case when a.invdate between '2020-05-09' and '2022-03-31' then case when  then case when    cast(Value as int)*5>5 then 5 else cast(Value as int)*5  end else  cast(Value as int) end  as value,c.QCount

FROM mobile.StatusReport a WITH (NOLOCK)
     INNER JOIN mobile.Question b WITH (NOLOCK) ON a.QuestionKey = b.PKey
                                               AND b.QuestionType = 'rate'
                                               AND InputType = 'numeric'
     INNER JOIN c WITH (NOLOCK) ON a.DivisionKey = c.DivisionKey1
     INNER JOIN d WITH (NOLOCK) ON a.HdrKey = d.HdrKey
                               AND a.QuestionKey = d.QuestionKey
WHERE a.QuestionHdrKey = '200305685377000000'
  --and  a.HdrKey='210305757994230000'
  AND d.RowId <= c.QCount
GROUP BY a.DivisionKey,
         a.InvDate,
         a.QuestionHdrKey,
         a.HdrKey,
         c.QCount;

我在 PowerBI 中查詢了這個表,它生成了下表:

查詢表的示例圖像

SQL 已在 Information Design Tool 中成功驗證,但在嘗試查看其值時,代碼中顯示錯誤。 我該如何解決這個問題?

好吧,在弄清楚“with as”在 IDS 中的選擇函數之外不起作用之后,我放棄了別名並使用了子查詢。

    select HdrKey,a.DivisionKey,InvDate,RowId ,count(b.QuestionKey) as QCount,qCOUNT_,[value],POINT
from 

(select  distinct  a.HdrKey,a.DivisionKey, a.InvDate, ROW_NUMBER()   OVER(PARTITION BY QuestionHdrKey, DivisionKey, a.InvDate ORDER BY a.InvDate) AS RowId,
sum(cast([value] as int)) AS [value], COUNT(DISTINCT A.QuestionKey) AS qCOUNT_, SUM(B.Rate) AS POINT
    from NominInventory.mobile.StatusReport a with(nolock)
    inner join NominInventory.mobile.Question b with(nolock) on a.QuestionKey=b.PKey and B.QuestionType = 'rate' and InputType='numeric'
    where a.QuestionHdrKey='200305685377000000'
    GROUP BY   a.HdrKey,a.DivisionKey, a.InvDate,QuestionHdrKey
    ) a
    inner join NominInventory.Mobile.QuestionLocationMap b with(nolock) on a.DivisionKey=b.DivisionKey and b.QuestionHdrKey = '200305685377000000'

    group by HdrKey,a.DivisionKey,InvDate,RowId,qCOUNT_,[value],POINT
    having a.RowId<=count(b.QuestionKey)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM