Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server : find rows that contains spaces

Tags:

sql

sql-server

I'm looking for a fast way to see all rows in my table that contain any spaces.

For starters, I tried to see which rows starts with a space with this query:

select * 
from MyTable 
where ColumnName like ' %'

but I got 0 results, although I can see there are rows with spaces.

like image 818
r.tom Avatar asked May 10 '26 19:05

r.tom


1 Answers

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.

like image 102
Sunil Cyriac Avatar answered May 12 '26 07:05

Sunil Cyriac



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!