【问题标题】:How to declare a variable as a parameter in excel microsoft query?如何在 excel microsoft 查询中将变量声明为参数?
【发布时间】:2020-02-04 03:32:15
【问题描述】:

我在excel中做了很多带有参数的sql查询,比如

Select ... from .. where x = ?

但后来我遇到了一个问题,我将一个变量声明为参数,然后出现错误Invalid parameter number

我的代码如下

Set NOCOUNT ON;
Declare @end_dt DATETIME2 = ?;
Select ... from ...

当我分配@end_dt = getdate()@end_dt = "2020-02-03" 时,它工作得很好。

有人对此有解决方案吗?

【问题讨论】:

    标签: sql excel


    【解决方案1】:

    你应该先声明变量然后设置。

    Set NOCOUNT ON;
    declare @end_dt as datetime
    set @end_dt = (select ..from ...)
    

    然后你可以在查询中使用 end_dt 变量

    select * from table where end_date = @end_dt;
    

    【讨论】:

    • 我也试过了,但还是报同样的错误
    猜你喜欢
    • 2010-12-02
    • 2012-09-25
    • 1970-01-01
    • 2017-04-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多