Reputation: 105
I'm looking for fast way to see all rows in table that contains any spaces.
For starters, I tried to see which rows starts with space by this query:
select *
from MyTable
where ColumnName like ' %'
but I got 0 results, although I can see there are rows with spaces.
Upvotes: 8
Views: 47148
Reputation: 31
try put another '%', this may solve your problem.
select * from MyTable where ColumnName like '% %'
Upvotes: 3
Reputation: 5094
Seem that those space contain some other special character apart from char(10).
Try this,
select *
from MyTable
where patindex('%[^A-Z0-9]%',ColumnName )>0
First decide what is valid value for ColumnName .Then try PATINDEX
and change the regex accordingly.
Upvotes: 3
Reputation: 523
Give this a try:
In SQL server you can use this:
SELECT * FROM MYTABLE
WHERE CHARINDEX(' ',ColumnName) > 0;
If you are using Oracle you can use this:
SELECT * FROM MYTABLE
WHERE INSTR(ColumnName,' ') > 0;
Essentially in this query it finds the character position containing first space from the column values and when it finds the first space in it the index value should be greater than 1 and it should display all the records based on that.
Upvotes: 17