select convert(varchar(10),cast(left(fbatchno,6) as datetime),120) from icinvinitial where left(fbatchno,2)='09' and len(fbatchno)=6以上是我的测试语句,出现错误
試下能不能撈到資料select left(fbatchno,6) from icinvinitial where left(fbatchno,2)='09' and len(fbatchno)=6 and isdate(left(fbatchno,6))=1
select left(fbatchno,6) from icinvinitial where left(fbatchno,2)='09' and len(fbatchno)=6 and isdate(left(fbatchno,6))=0 --用0,看有沒有資料
select convert(varchar(10),cast(left(fbatchno,6) as datetime),120) from icinvinitial where left(fbatchno,2)='09' and len(fbatchno)=6 and isdate(left(fbatchno,6))=0 --用0,看有沒有資料 服务器: 消息 242,级别 16,状态 3,行 5 从 char 数据类型到 datetime 数据类型的转换导致 datetime 值越界。
select convert(varchar(10),cast(left(fbatchno,4)+'01' as datetime),120) from icinvinitial where left(fbatchno,2)='09' and len(fbatchno)=6 and isdate(left(fbatchno,6))=1 测试成功,结贴
----------
2009-12-01(所影响的行数为 1 行)
**/
这样也是可以的
----------
2009-12-01
where left(fbatchno,2)='09'
and len(fbatchno)=6
and isdate(left(fbatchno,6))=1
select left(fbatchno,6) from icinvinitial
where left(fbatchno,2)='09'
and len(fbatchno)=6
and isdate(left(fbatchno,6))=0 --用0,看有沒有資料
服务器: 消息 242,级别 16,状态 3,行 5
从 char 数据类型到 datetime 数据类型的转换导致 datetime 值越界。