使用char(10)存储日期,为什么可以直接与sybase 15.7中的=进行比较

问题描述 投票:1回答:1

#report_tmp中的term_date是char(10),当使用<,>时,它按预期工作,这个比较方法在sybase中是否可靠?

    declare @last_year_end char(10)

SELECT @last_year_end=convert(varchar,@cyear -1)+'/12'+'/31'


update #report_tmp
set remark = @note1
where term_date != '' and term_date <= @last_year_end
sybase sybase-ase
1个回答
2
投票

我宁愿写这段代码:

declare @cur_year datetime

SELECT @cur_year = convert(datetime, convert(varchar, @cyear) + '/01'+'/01', 111)

update #report_tmp set remark = @note1 
where term_date != '' and term_date < @cur_year

在将varchar隐式转换为date或datetime时,您不依赖于当前的语言环境设置(可以同时使用)。

© www.soinside.com 2019 - 2024. All rights reserved.