How can I get this example to display ('space') and ('space ')?
create table #example
(
myString varchar(50)
)
insert into #example values ('space'), ('space ')
select distinct *
from #example
I am aware SQL comparison operators consider these two strings as equivalent, but I do not for this case.
https://support.microsoft.com/en-us/kb/316626
SQL WHERE clause matching values with trailing spaces
Follow-up to answer:
Note: the DATALENGTH(...)
function can also produce a join sensitive to trailing whitespace:
select *
from table1
left join table2 on table1.id1 = table2.id1
and datalength(table1.id1) = datalength(table2.id1)