Tom
Tom

Reputation: 121

Store date with char(10), why can compare directly with <,>,= in sybase 15.7

The term_date in #report_tmp is char(10), when use <,>, it works as expect, Is this comparison method reliable in 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

Upvotes: 1

Views: 154

Answers (1)

Adam Leszczyński
Adam Leszczyński

Reputation: 1161

I would rather write this code:

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

Here the you do not rely on the current locale settings when implicitly converting the varchar to date or datetime (would work with both).

Upvotes: 2

Related Questions