nvarchar转换为date类型后,对下面view中的日期查询出错

ChinaITOldMan ChinaITOldMan 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
表t1中的f1为nvarchar, 该字段f1里面存储有字符或日期类型的数据, 现在我通过条件过滤出只有日期格式的数据,通过vwDate1过滤出f1中只有日期格式的数据, 若执行 select * from vwDate1 (vwDate1为下面的视图) 执行成功,查询出来的数据是日期类型的, 但是若用select * from vwDate1 where f1>'2019-5-1' 就显示 Conversion failed when converting date and/or time from character string.

若 select * into #tt1 from vwDate1 再执行select * from #tt1 where f1>'2019-5-1' 执行成功。
请问通过view进行转换的方式,是否有办法直接执行 select * from vwDate1 where f1>'2019-5-1' 不会出错,也就是我不想通过生成临时表而直接查询View的方式进行查询。



CREATE VIEW vwDate1
AS
select convert(DATE, f1 ) AS f1, f2, f3 from t1
where f3='date'

谢谢!
...全文

相关推荐

评论 9
收藏 已收藏
分享
返回顶部
ChinaITOldMan
疑难问题 22,298 成员 121,727 内容