Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display all records with leading or trailing spaces

I am looking for a SQL query (Using SQL 2008) to search various fields that I specify (or even all fields in particular tables) for leading or trailing spaces. I would like the output to be two columns with the following data:

ID Number, Data (that has the space), Field Name

Thanks for the help as usual!

like image 437
user3513237 Avatar asked Jun 12 '15 22:06

user3513237


2 Answers

You can use DATALENGTH

SELECT ID, Data, FieldName
FROM table
WHERE DATALENGTH(RTRIM(LTRIM(Data))) <> DATALENGTH(Data)
like image 99
freakinthesun Avatar answered Sep 22 '22 01:09

freakinthesun


Try:

select `ID Number`, `Data (that has the space)`, `Field Name` from tbl WHERE data like ' %' or data like '% '
like image 39
hd1 Avatar answered Sep 19 '22 01:09

hd1