sql server 2008 - parameterized Sql Query in R not working -
i have query in r extracts info sql server takes column values command line arguments. not result in output.
library(rodbc) argv <- commandargs(true) dbhandle <- odbcdriverconnect('driver={sql server};server=<srvr_nm>; database=<db>; trusted_connection=true') res <- sqlquery(dbhandle, 'select * table col = \'argv[1]\'')
this how calling it
c:\users\uid>"c:\program files\r\r-3.1.0\bin\x64\rscript.exe" --slave --vanilla "c:\r\script.r" "abc"
(even if remove quotation command line argument while passing dies not help)
the output is:
<0 rows> (or 0-length row.names)
when saw getting passed had quotation mark... e.g. "abc"... value stored in table abc (without quotation). tried remove quotation
as.name(argv[1])
but did not help...
then inserted value in table quotation "abc" (instead of abc)... still not getting selected.
can help me in query.
try fn$
in gsubfn package:
library(gsubfn) argv <- gsub('"', '', commandargs(true)) # remove double quotes # ... res <- fn$sqlquery(dbhandle, "select * table col = '`argv[1]`' ")
or replace lastly line with:
argv1 <- argv[1] res <- fn$sqlquery(dbhandle, "select * table col = '$argv1' ")
r sql-server-2008
No comments:
Post a Comment