Sql 将Power查询中的日期变量传递到ODBC源

Sql 将Power查询中的日期变量传递到ODBC源,sql,sql-server,excel,powerbi,powerquery,Sql,Sql Server,Excel,Powerbi,Powerquery,我已经成功地从Excel中提取了一个日期,用户可以修改该日期。[一个名为DateB的命名范围]。 我希望能够将其传递给powerquery的sql部分中的一个变量,以便在返回数据之前进行各种检查。但是,我无法让变量@man_Date接受我提取的日期 RDP3在该阶段正确返回2020年6月30日 然而,在源代码部分,如果我有&RDP3&我被告知它不会与&s一起工作 如果我删除它们,则会留下错误消息标记逗号 这是我在查询开始时的代码。我还在子查询中使用@Man_Date RDP3的正确语法是什么?

我已经成功地从Excel中提取了一个日期,用户可以修改该日期。[一个名为DateB的命名范围]。 我希望能够将其传递给powerquery的sql部分中的一个变量,以便在返回数据之前进行各种检查。但是,我无法让变量@man_Date接受我提取的日期

RDP3在该阶段正确返回2020年6月30日

然而,在源代码部分,如果我有&RDP3&我被告知它不会与&s一起工作 如果我删除它们,则会留下错误消息标记逗号

这是我在查询开始时的代码。我还在子查询中使用@Man_Date

RDP3的正确语法是什么? @Man_日期与手动输入一起使用@Man Date='2020-06-30' 我尝试过各种各样的日期格式,但似乎无法实现。 看起来这两个部分都是独立工作的。只是把它们绑在一起才是症结所在

let
    //
    RDP = Excel.CurrentWorkbook(){[Name="DateB"]}[Content],
    RDP2 = Table.TransformColumnTypes(RDP,{{"Column1", type date}}),
    RDP3 = RDP2{0}[Column1],
    //
Source = Odbc.Query("dsn=xxxxxxxxxxx", "

--PI Payments Due
SET NOCOUNT ON;
DECLARE @man_Date DATETIME --Manual Date
SET @man_Date = " & RDP3 & "

select qry1.*,
case when [Invoice Due Date] > @man_Date or datediff(d,[Invoice Due Date], @man_Date) = 0 then [Sterling Balance Due] else 0 end as 'Current',
case when datediff(d,[Invoice Due Date], @man_Date) >   0 and datediff(d,[Invoice Due Date], @man_Date) <=  30 then [Sterling Balance Due] else 0 end as '0-30',
case when datediff(d,[Invoice Due Date], @man_Date) >  30 and datediff(d,[Invoice Due Date], @man_Date) <=  60 then [Sterling Balance Due] else 0 end as '31-60',
case when datediff(d,[Invoice Due Date], @man_Date) >  60 and datediff(d,[Invoice Due Date], @man_Date) <=  90 then [Sterling Balance Due] else 0 end as '61-90',
case when datediff(d,[Invoice Due Date], @man_Date) >  90 and datediff(d,[Invoice Due Date], @man_Date) <= 120 then [Sterling Balance Due] else 0 end as '91-120',
case when datediff(d,[Invoice Due Date], @man_Date) > 120  then [Sterling Balance Due] else 0 end as 'Over 120'

from (

    select  VD.vcd_voucherno as 'Invoice No',VD.vcd_voucherdate as 'Date Raised',  PTY_NmeParty as 'Name' ,
    PTY_ValBuyerCreditLimit as 'Credit Limit',vd.vcd_currencycode as 'Currency',
    vd.vcd_amount * case when vd.vcd_debitorcredit = 'D' then -1 else 1 end as 'Invoice Amount', 
    (coalesce(sum(SOC.sof_crsetoffamount),0) - coalesce(sum(SOD.sof_drsetoffamount),0)) as 'Amount Paid',

我现在已经知道,我只能将文本传递给sql。 因此,我使用下面的分解将日期转换为SQL的文本形式

let
//
RDC1 = Excel.CurrentWorkbook(){[Name="DateB"]}[Content],
RDC2 = Table.TransformColumnTypes(RDC1,{{"Column1", type date}}),
RDC3 = RDC2{0}[Column1],
RDC4 = Date.ToText(RDC3, "yyyy")&"-"&Date.ToText(RDC3, "MM")&"-"&Date.ToText(RDC3, "dd"),
// Source = Odbc.Query("dsn=xxxxxxxx", "#(lf)#(lf)--PI Payments Due#(lf)SET NOCOUNT ON;#(lf)DECLARE @man_Date DATETIME --Manual Date#(lf)SET @man_Date = **'" &Text.From(RDC4)& "'**  #(lf)Select etc
RDC4部分将其转换为可用的文本日期,并在整个查询中使用


希望这对其他人有所帮助。

作为进一步说明,我可以设置man_Date=getdate。我还可以设置mandate=getdate-2。我不能做的是获取man_Date=getdate-[value from excel cell]。我想知道是否还有其他方法可以做到这一点