我正在使用RODBC
包来从数据库中查询文本列。该数据库建立在Microsoft SQL Server 2008 R2上。 SQL中列的数据类型是nvarchar(max)
。当它应该返回varchar(MAX)时,RODBC sqlQuery()返回varchar(255)
然而,当我运行:
# Set up ODBC connection to CCWEB5 production server
# Note: default database is set to "CCSalary"
ccweb5.prod <- odbcConnect("ccweb5")
# Read in some job ad text
job.text <- sqlQuery(ccweb5.prod,"
SELECT TOP 100
ja.JobTitle,
ja.JobText as 'JobText',
LEN(ja.JobText) as 'JobTextLength'
FROM JobStore.dbo.JobAd as ja (NOLOCK)
")
在SQL,我期待(对于顶行):
JobTitle JobText JobTextLength
IT Field Service Technician <text goes here...> 2742
然而,当我这样做:nchar(as.character(job.text[1,2]))
它返回:。
所以我的问题是,是什么导致这种截断,我该如何避免它?谢谢!!