Excel Postgresql 数据库连接使用单元格作为日期
Excel Postgresql Database Connection Use Cell as Date
我正在尝试为使用单元格值作为日期参数的数据库编写 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
我读了这个 post:
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
查询将不再有效,因为我收到无效语法警告。我应该如何正确构造此查询?非常感谢任何帮助。
编辑:
我取出引号并尝试使用 none 日期参数执行此操作,现在我收到消息 "the # of binded parameters < the # of parameter markers"
我找到了解决问题的最佳方法。您可以像这样修改使用查询:
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 将询问参数。然后参数按钮将显示在连接属性中,以便您可以编辑参数。
我正在尝试为使用单元格值作为日期参数的数据库编写 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
我读了这个 post: 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
查询将不再有效,因为我收到无效语法警告。我应该如何正确构造此查询?非常感谢任何帮助。
编辑:
我取出引号并尝试使用 none 日期参数执行此操作,现在我收到消息 "the # of binded parameters < the # of parameter markers"
我找到了解决问题的最佳方法。您可以像这样修改使用查询:
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 将询问参数。然后参数按钮将显示在连接属性中,以便您可以编辑参数。