comparison - TSQL compare varchar in digit form -
basically did comparison in tsql below
if ('500' > '400') print('no problem') else print('error')
so, in situation, comparison should no problem
if ('2500' > '400') print('no problem') else print('error')
however, when situation above appeared, 'error' print. basically, code comparison base on first character of strings. can explain?
extra question: if insist compare strings without casting int or double. how can it?
when compare varchar
values, comparison lexicographical i.e. according alphabetical order. therefore, if treat 2 numeric values strings, compared strings too. means need convert strings numeric type if want compare numeric value.
Comments
Post a Comment