Microsoft SQL:找不到列" dbo"或用户定义的函数或聚合

时间:2017-03-02 16:34:18

标签: sql sql-server excel powerquery

我是SQL新手并尝试使用Power Query直接使用UDF将Great Plains数据拉入Excel,我发现here将参数从工作簿传递到查询。这是UDF:

(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:找不到列" dbo"要么   用户定义的函数或聚合" dbo.fnGetParameter"或者   名字含糊不清。细节:       DataSourceKind = SQL       DataSourcePath = dcb-gp15-sql.us.medsolutions.com; MED01       消息=找不到列" dbo"或用户定义的函数或聚合" dbo.fnGetParameter",或   这个名字含糊不清。       数= 4121       类= 16

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

习俗" M"函数fnGetParameter仅在Power Query中运行mashup时定义,并且不会发送到服务器。

如果您从Power Query指定本机SQL查询,那就是我们发送给服务器的字面意思。 Power Query没有为您提供在服务器上定义自定义UDF的方法。

相反,您可以将AccountTransactions表导入Power Query,然后使用" M"变换转换表。我建议使用UI生成行过滤器和求和聚合,然后自定义" M"使用您的客户过滤器。

e.g。你的一个步骤是:

FilteredRows3 = Table.SelectRows(
    FilteredRows2,
    each
        fnGetParameter("Lookback for Automated Accruals") < [TRX Date] 
      and 
        [TRX Date] < fnGetParameter("Accrual Date")
)