RODBC loses time values of datetime when result set is large

后端 未结 8 1801

So this is VERY strange. RODBC seems to drop the time portion of DateTime SQL columns if the result set is large enough. (The queries are running against an SQL S

相关标签:
8条回答
  • 2020-12-14 21:57

    Why this happens on large datasets returned from sqlQuery()? I don't know. But was able to workaround it by applying a sql conversion in the sql call:

    data <- sqlQuery(channel, "SELECT CONVERT(nvarchar(24), DtTimeField, 21) AS HourDt, * FROM ...

    This is your workaround.

    0 讨论(0)
  • 2020-12-14 21:58

    This is an older question, but I had similar issues when trying to programmatically read in data from 15 different .accdb. All POSIXct fields were read in correctly for every database except those from the months of March, from which I inferred that it is some sort of daylight-savings time issue.

    The solution for me (because I didn't want to have to make multiple queries to a dB and then rbind() everything together) was to alter my function to include the lines

    #Get initial tz
    current_tz <- Sys.timezone()
    Sys.setenv(TZ = "America/Phoenix")
    
    [BODY OF FUNCTION]
    
    Sys.setenv(TZ = curent_tz)
    

    After including these few lines, the day/time fields from the March databases were being read in correctly.

    0 讨论(0)
提交回复
热议问题