nvarchar转换为date类型后,对下面view中的日期查询出错
表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'
谢谢!