[R] [RODBC] date attribute in sqlQuery

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Aug 12 11:53:10 CEST 2008

On Tue, 12 Aug 2008, Abderrazzak MANY wrote:

> Hello R users,
> I would like to use an integer and a date as attributes in sqlQuery, and 
> these arguments
> are defined in my function.
> Here is my function:
> GetReturn<-function(code,date)
> {
> channel<-odbcConnect("db","user1","password")
> ssql<-paste("select * from TABLE Where PF_CODE =",code,"and PF_DATE=",date)
> mydata<-sqlQuery(channel,ssql)
> mydata
> }
> Actually, the channel is open but the query on the table did not work.

How about reading the posting guide and showing us the actual code and 
what 'did not work' meant?

You haven't told us which DBMS this is (nor any other of the information 
asked for in the posting guide): the SQL syntax for dates is 
DBMS-specific, but I would expect you to need to quote the date.

> The command paste worked for the integer argument but not for the date.
> Thank you for helping.

We need a lot more information to do more than guess.

> A.Many
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-help mailing list