我是SQL新手,嘗試使用Power Query將Great Plains數據直接使用UDF向Excel中發送,我發現here可以傳遞參數從工作簿到查詢。這裏是UDF:Microsoft SQL:無法找到列「dbo」或用戶定義的函數或聚合
(ParameterName as text) =>
let
ParamSource = Excel.CurrentWorkbook(){[Name="Parameters"]}[Content],
ParamRow = Table.SelectRows(ParamSource, each ([Parameter] = ParameterName)),
Value=
if Table.IsEmpty(ParamRow)=true
then null
else Record.Field(ParamRow{0},"Value")
in
Value
,這裏是SQL查詢:
Declare @accrualDate Date
set @accrualDate = dbo.fnGetParameter("Accrual Date")
Declare @lookback Date
set @lookback = dbo.fnGetParameter("Lookback for Automated Accruals")
Declare @lookbackBOP Date
set @lookbackBOP = dbo.fnGetParameter("Lookback for Manual Accruals - BOP")
Declare @lookbackEOP Date
set @lookbackEOP = dbo.fnGetParameter("Lookback for Manual Accruals - EOP")
SELECT
[Open Year],
[History Year],
[Period ID],
[TRX Date],
[Account Number],
[Account Description],
[Journal Entry],
[description],
[reference],
[Originating Posted Date],
Sum([Debit Amount]) AS [Debit Amount],
Sum([Credit Amount]) AS [Credit Amount] ,
Segment1,
Segment2,
Segment3,
Segment4,
Segment5,
Segment6,
Segment7
FROM ['dbName'].[dbo].[AccountTransactions]
WHERE Segment2 BETWEEN 6000 AND 6999
and [description] = 'Purchases'
and [TRX Date] BETWEEN @lookback AND @accrualDate
GROUP BY [Open Year], [History Year], [Period ID], [TRX Date], [Account Number], [Account Description], [Journal Entry],[description],[reference], [Originating Posted Date], Segment1, Segment2, Segment3, Segment4, Segment5, Segment6, Segment7
我已經通過自身運行UDF,並且已經證實,它從我的「參數」表返回預期值。但是,運行查詢時出現以下錯誤:
DataSource.Error: Microsoft SQL: Cannot find either column "dbo" or the user-defined function or aggregate "dbo.fnGetParameter", or the name is ambiguous. Details: DataSourceKind=SQL DataSourcePath=dcb-gp15-sql.us.medsolutions.com;MED01 Message=Cannot find either column "dbo" or the user-defined function or aggregate "dbo.fnGetParameter", or the name is ambiguous. Number=4121 Class=16
任何幫助將不勝感激。
什麼是'dbo.fnGetParameter'?如果它是[表值函數](https://technet.microsoft.com/en-us/library/ms191165(v = sql.105).aspx),那麼你不能將它用作標量函數 –
是' fnGetParameter是一個Excel函數?目前尚不清楚。 – DavidG
fnGetParameter是我使用Power Query> From Other Sources>空白查詢>高級編輯器創建的UDF的名稱。對不起,我應該在問題中更清楚一點。 – battery514