【问题标题】:Excel Postgresql Database Connection Use Cell as DateExcel Postgresql 数据库连接使用单元格作为日期
【发布时间】:2015-08-20 12:39:13
【问题描述】:

我正在尝试为使用单元格值作为日期参数的数据库编写 SQL 命令。这是一个没有单元格值的示例查询:

SELECT usda_cattle_auctions.weight_average, usda_cattle_auctions.average_price
FROM public.usda_cattle_auctions usda_cattle_auctions
WHERE (usda_cattle_auctions.report_date>={d '2012-03-24'} And usda_cattle_auctions.report_date<={d '2014-10-25'}) AND (usda_cattle_auctions.state='CO') AND (usda_cattle_auctions.gender='Steers') AND (usda_cattle_auctions.class_type='Feeder')
ORDER BY usda_cattle_auctions.report_date DESC

我读了这篇文章: Excel: Use a cell value as a parameter for a SQL query

但是当我像这样调整一个参数时:

SELECT usda_cattle_auctions.weight_average, usda_cattle_auctions.average_price
FROM public.usda_cattle_auctions usda_cattle_auctions
WHERE (usda_cattle_auctions.report_date>={d [MarketValCal$d3]} And usda_cattle_auctions.report_date<={d '2014-10-25'}) AND (usda_cattle_auctions.state='CO') AND (usda_cattle_auctions.gender='Steers') AND (usda_cattle_auctions.class_type='Feeder')
ORDER BY usda_cattle_auctions.report_date DESC

查询将不再有效,因为我收到了无效的语法警告。我应该如何正确构建此查询?非常感谢任何帮助。

编辑:

我取出引号并尝试使用无日期参数来执行此操作,现在我收到消息“绑定参数的数量

【问题讨论】:

    标签: sql excel postgresql database-connection


    【解决方案1】:

    我找到了解决问题的最佳方法。您可以像这样修改使用查询:

    SELECT usda_cattle_auctions.weight_average, usda_cattle_auctions.average_price
    FROM public.usda_cattle_auctions usda_cattle_auctions
    WHERE (usda_cattle_auctions.report_date>= ? And usda_cattle_auctions.report_date<={d '2014-10-25'}) AND (usda_cattle_auctions.state='CO') AND (usda_cattle_auctions.gender='Steers') AND (usda_cattle_auctions.class_type='Feeder')
    ORDER BY usda_cattle_auctions.report_date DESC
    

    通过转到数据选项卡下的连接属性并单击定义来修改查询。只需替换命令文本,单击确定后,excel 将询问参数。然后参数按钮将显示在连接属性中,以便您可以编辑参数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-18
      • 1970-01-01
      • 2011-12-12
      • 2013-04-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多