Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
I have a table with a name column. It contains many different format of data, for example -John SmithJohn J. SmithMr. John SmithI'm asked to return rows with only one space in the string, like 'John Smith', with one query. Can anybody help me with it?Thanks,George
ygeorge
Yak Posting Veteran
68 Posts
Posted - 2004-07-16 : 12:49:39
Just figured out - select name from table_name where name like '% %' and name not like '% % %'
X002548
Not Just a Number
15586 Posts
Posted - 2004-07-16 : 13:02:49
How's about:
USE NorthwindGOCREATE TABLE myTable99(Col1 varchar(20))GOINSERT INTO myTable99(Col1)SELECT 'John Smith' UNION ALLSELECT 'John J. Smith' UNION ALLSELECT 'Mr. John Smith'GOSELECT * FROM myTable99WHERE LEN(Col1) - LEN(REPLACE(Col1,' ','')) = 1GODROP TABLE myTable99GO