我已经使用DBI::dbGetQuery
.
即使在真正的查询(不是下面的播放查询)中,
select convert(date, date_value) as date_value
日期仍然存储为字符。
然后我尝试使用 改变代表日期的字符lubridate::ymd
,但是我收到一条消息说
未找到日期值
我也试过了,convert(date, date_value)
没用as.Date
。
require(dplyr)
if (dbExistsTable(con, "##temp", catalog_name = "tempdb")){
dbRemoveTable(con, "##temp")
}
DBI::dbGetQuery(con, paste(
"select
convert(date, '2013-05-25') as date_value
into ##temp
"))
tbl(con, "##temp")
# Error - date_value not found
tbl(con, "##temp") %>% mutate(date_value= lubridate::ymd(date_value))
# this works
tbl(con, "##temp") %>% mutate(temp= date_value)
# this doesn't work - date value not found
tbl(con, "##temp") %>% mutate(temp= lubridate::ymd(date_value))
如何将此字段用作日期?
注意:当我在 SQL Server 中编写以下内容时,date_value 显示为日期类型
select
convert(date, '2013-05-25') as date_value
into #hello
select *
from #hello
exec tempdb..sp_help #hello