简体   繁体   English

RODBC-导入表

[英]RODBC - import a table

I would like to import a table but with a dynamic date that I have in vector "Daty". 我想导入一个表格,但要在向量“ Daty”中输入一个动态日期。 My problem is that I can not import a table with date as a variable. 我的问题是我无法导入带有日期作为变量的表。

                select
                    Symbol
                ,   OpenTime
                from
                    xxx t
                inner join
                    zzz i
                on
                    t.xxxxx = i.zzzzzz
                where
                    OpenTime between '",Daty[1],"' and '",,"'
                and Symbol like '%xxx%'

When I do: 当我做:

x <- sqlQuery(ch, query)

R is not able to import this table. R无法导入该表。

The variable query must be a string. 变量query必须是字符串。 One way of including variables in the query is using paste0() 在查询中包括变量的一种方法是使用paste0()

query <- paste0(
  "select
    Symbol
  , OpenTime
  from
  xxx t
  inner join
  zzz i
  on
  t.xxxxx = i.zzzzzz
  where
  OpenTime between '",
  Sys.Date(), # first date Daty[1] in your case
  "' and '",
  Sys.Date() + 1, # second date
  "' and Symbol like '%xxx%'"
)

This returns (using cat(query) ): 这将返回(使用cat(query) ):

select
    Symbol
  , OpenTime
  from
  xxx t
  inner join
  zzz i
  on
  t.xxxxx = i.zzzzzz
  where
  OpenTime between '2017-10-20' and '2017-10-21' and Symbol like '%xxx%'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM