SQL - Why a parameter is truncated

I have a table (t) with column (c) defined as varchar 20 containing the values ​​'a', 'b' and 'c'

If I execute the following sql, the value is returned:

select * from table where c = 'a    '

Why?

I assume it somehow throws / truncates the parameter, but why?

How I really looked 'a '

+3
source share
3 answers

varchar, varchar. Varchar . , , VARchar. char , . ( LEN():

 declare @a varchar(20) = 'a     '
 select * from t where c = @a and len(@a) = Len(c)
+1

I used a simple solution:

declare @a varchar(20) = 'a     '
select * from t where c + '$' = @a  + '$'
0
source

Source: https://habr.com/ru/post/1716862/


All Articles