SQL查询中的Excel数据参数

时间:2022-01-17 23:02:59

I use an SQL query to retrieve a data table from an oracle database with excel.

我使用SQL查询从oracle数据库中使用excel检索数据表。

When a fixed date is used I get this request:

当使用一个固定的日期时,我收到以下请求:

SELECT * FROM MyTable WHERE MyTable.Date > {ts '2014-09-30 00:00:00'}

What I would like to do is replace the fixed date by a date from a cell. I tried the folowing:

我想做的是用单元格中的日期替换固定的日期。我试着关注:

SELECT * FROM MyTable WHERE MyTable.Date > ?
SELECT * FROM MyTable WHERE MyTable.Date > {ts ?}
SELECT * FROM MyTable WHERE MyTable.Date > {ts '?'}
SELECT * FROM MyTable WHERE MyTable.Date > {ts [?]}
SELECT * FROM MyTable WHERE MyTable.Date > {ts ['?']}

None of it worked. I don't know where to go from there. In the end I'd like the date cell to work in either american (12/31/2014) or international (31/12/2014) configuration.

无一奏效。我不知道从那里去哪里。最后,我希望日期单元格在american(12/31/2014)或international(31/12/2014)配置中工作。

1 个解决方案

#1


1  

If the date is stored in the cell A1 using Excel date format then to pass it as a parameter to the query you must do as follow:

如果日期存储在单元A1中,使用Excel日期格式,然后将其作为参数传递给查询,您必须这样做:

1 - Transform the date format to a correct date string in cell B2 for obdc:

1 -将日期格式转换为obdc单元B2中的正确日期字符串:

= LOWER(TEXT(D2,"dd-mmmm-yyyy"))

2 - Pass the B2 cell as a paremeter with the query:

2 -将B2单元作为参数传递给查询:

SELECT * FROM MyTable WHERE MyTable.Date > ?

#1


1  

If the date is stored in the cell A1 using Excel date format then to pass it as a parameter to the query you must do as follow:

如果日期存储在单元A1中,使用Excel日期格式,然后将其作为参数传递给查询,您必须这样做:

1 - Transform the date format to a correct date string in cell B2 for obdc:

1 -将日期格式转换为obdc单元B2中的正确日期字符串:

= LOWER(TEXT(D2,"dd-mmmm-yyyy"))

2 - Pass the B2 cell as a paremeter with the query:

2 -将B2单元作为参数传递给查询:

SELECT * FROM MyTable WHERE MyTable.Date > ?