[英]power query excel table mssql returns invalid column name
這是我的客戶參數表
let
Source = Excel.CurrentWorkbook(){[Name="Customer"]}[Content],
Customer1 = Source{0}[Customer]
in
Customer1
我的查詢
let
Customer = Excel.CurrentWorkbook(){[Name="Customer"]}[Content],
Customer_Name = Customer{0}[Customer],
Source = Sql.Database("SERVER", "DATABASE", [Query="SELECT i.PriorityType as 'PRIORITY','COUNT' = COUNT(i.IncidentID)#(lf)FROM ININ_ISupport_S_Incident_Search2 (NULL) i#(lf)WHERE IncidentType IN ('Customer Support','Managed Services')#(lf)AND Organization = Customer_Name#(lf)AND IsResolved = 0#(lf)AND Active = 1#(lf)AND StateType = 'Open'#(lf)GROUP BY i.PriorityType#(lf)ORDER BY CASE#(lf) WHEN i.PriorityType = 'Code Red' THEN 1#(lf) WHEN i.PriorityType = 'Code Red RCA' THEN 2#(lf) WHEN i.PriorityType = 'High' THEN 3#(lf) WHEN i.PriorityType = 'Medium' THEN 4#(lf) WHEN i.PriorityType = 'Low' THEN 5#(lf)END ASC"])
in
Source
我正在設置Organization = Customer_Name但我繼續得到以下內容
Message=Invalid column name 'Customer_Name'
有沒有辦法實現這一目標
Customer_Name不是SQL表中的列,因此它失敗並顯示該消息。 如果要在查詢中使用Customer_Name,則需要將其添加到字符串中。 這是使用&運算符完成的。 在你的情況下,你會做類似的事情
"...AND Organization = '" & Customer_Name & "'#(lf)AND IsResolved...
如果客戶名稱中有引號(如O'Neill),這將導致問題,所以你可以這樣做
"...AND Organization = '" & Text.Replace(Customer_Name, "'", "''") & "'#(lf)AND IsResolved...
試圖逃避報價。
轉義引號並不總是足夠的,因此如果您在外部人員可以創建客戶的數據庫上運行此查詢,則應避免使用上述方法。 如果按Customer_Name篩選列(通過Table.SelectRows(tableName, each [Organization] = Customer_Name)
),則應該得到相同的結果而不存在任何安全問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.