Domanda

I need to read from a data base where one of the columns contains 'T' and 'F' values using RODBC sqlQuery function. However my results keep coming out with 'TRUE' and 'FALSE'. I found the following post for reading csv files. Is there a similar workaround for the sqlQuery function?

read.table reads "T" as TRUE and "F" as FALSE, how to avoid?

Edit : This is the code I'm running as requested in the comments. It won't be executable without access to the DB though ...

conn = odbcConnect(dataBaseName)
results = sqlQuery(conn, paste0("select ID, andate, antime from table.e4 where ticker in (",paste(shQuote(IDvector, type = "sh"), collapse = ', '),");"))
close(conn)

ID is the field that contains 'T's and 'Fs

È stato utile?

Soluzione

sqlQuery function has as.is option, from the RODBC manual:

as.is which (if any) columns returned as character should be converted to another type? Allowed values are as for read.table. See ‘Details’.

Details
... if as.is is true for a column, it is returned as a character vector. Otherwise (where detected) date, datetime and timestamp values are converted to the "Date" or "POSIXct" class. ...

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top