[R] sqlQuery with date attribute
Samuel Bächler
linux at boeser.ch
Wed Aug 13 12:02:29 CEST 2008
Hi Many
> GetReturn<-function(code,date)
> {
> db<-"C:/Test.mdb"
> channel<-odbcConnectAccess(db)
> ssql<-paste("select * from tblCalendarDate Where CalendarID
> =",code,"and DateRebal >=",date)
> print(ssql) # so as i can see what ssql contains
> mydata<-sqlQuery(channel,ssql)
> mydata
> }
[snip]
> This is the content of my table tblCalendarDate:
> CalendarID DateRebal
> 1 29/09/2006
> 1 10/10/2006
> 1 20/10/2006
> 1 31/10/2006
> 1 10/11/2006
> 1 20/11/2006
>
> Actually, the channel is open but the query on the table did not
> perform the query correctly, here is the
> result of the function when i run GetReturn(1,"2007-03-01") for example:
Something with the formatting of the date goes wrong as I think. In the
table tblCalendarDate you have it
like *29/09/2006* but in your function you have it as *"2007-03-01"*.
Dig deeper by experimenting with
the dates format. You can experiment in Access itself to see what kind
of dates Access accepts.
s.
More information about the R-help
mailing list