Ho un database SQL (2012) a cui sto tentando di accedere tramite R (R Studio). Da Enterprise Manager questo è ciò che sembra:Gestione RODBC delle date dal server SQL
select top 5[date],value from dbo.history
1991-02-11 11.1591
1991-02-12 11.2
1991-02-13 11.3501
1991-02-14 11.37
1991-02-15 11.3002
Tuttavia da R questo è ciò che ottengo:
sqlQuery(DF_CN,'select top 5 [date],value from dbo.history')
date value
1 0011-02-19 11.16
2 0012-02-19 11.20
3 0013-02-19 11.35
4 0014-02-19 11.37
5 0015-02-19 11.30
Quando provo e selezionare tutti i dati dalla tabella, questo è ciò che ottengo
sqlQuery(DF_CN,'select * from dbo.history')
Error in charToDate(x) :
character string is not in a standard unambiguous format
può essere qualcosa circa il formato di default aaaa-mm-gg dal server SQL che posso cambiare se uso CONVERT
, ma questo sembra un hack e la SELECT *
wou Non lavoro.
C'è qualcosa in R Posso fare per riconoscere le date di SQL Server?
Ben
Questo mi sta facendo impazzire - sicuramente qualcuno ha visto questo prima - v'è una chiara discrepanza tra l'uscita di SQL Server e ciò che R è la lettura.
Sto usando RStudio 0.98.1091 e R x64 3.1.2. Sql Server 2014 Microsoft SQL Server Management Studio 12.0.2000.8 Microsoft Data Access Components (MDAC) 6.1.7601.17514 Microsoft MSXML 3.0 4.0 6.0 Microsoft Internet Explorer 9.10.9200.17148 Microsoft .NET Framework 4.0.30319.18444 sistema operativo 6.1. 7601
Driver ODBC 11 per SQL Server.
Tutto sembra aggiornato sul mio sistema.
la colonna [date]
era di tipo DATE
, è ora DATETIME
. Ora capisco questo;
sqlQuery(DF_CN,('select * from dbo.history')
Error in as.POSIXlt.character(x, tz, ...) :
character string is not in a standard unambiguous format
Sembra una disconnessione tra l'installazione del server SQL e l'installazione R.
Stai Memorizzazione le date come valori datetime o valori VARCHAR nella tabella SQL? In caso di quest'ultimo, prendere in considerazione la possibilità di cambiarli in valori DATETIME, che dovrebbero essere gestiti meglio da R. – Dan
Le date vengono archiviate come DATETIME nel database di SQL Server –