Re: [R] sqlQuery with date attribute

From: Abderrazzak MANY <amany_at_messel.emse.fr>
Date: Wed, 13 Aug 2008 10:07:23 +0200

Thank you for your answer.
Actually, I've tried with this function where I added the # symbol between the date:

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
}
GetReturn(1,"2007-01-10")

And it works when I run simply the command GetReturn(1,"2007-03-01")

"Samuel Bächler" <linux_at_boeser.ch> a écrit :

> 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.
>
> ______________________________________________
> 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.
>

______________________________________________
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. Received on Wed 13 Aug 2008 - 08:14:11 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 13 Aug 2008 - 08:33:38 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive