views:

59

answers:

2

How can I find all column values in a column which have trailing spaces? For leading spaces it would simply be

select col from table where substring(col,1,1) = ' ';
+6  A: 

SELECT col FROM tbl WHERE col LIKE '% '

Jaxidian
+1  A: 

SQL Server 2005:

select col from tbl where right(col, 1) = ' '

As a demo:

select 
    case when right('said Fred', 1) = ' ' then 1 else 0 end as NoTrail,
    case when right('said Fred ', 1) = ' ' then 1 else 0 end as WithTrail

returns

NoTrail WithTrail
0       1  
Neil Moss