Query

  • I have a table with data like this example:

    Pedro

    Pedro Martins

    Maria

    Maria Ana Marta

    Monica

    Monica2

    Monica1

    Monica azenha

    I what that the query selects only names that have a space. If the name is a single word i want that it be excluded from the results.

    Can some one help?

    Thanks.

    P.S - Example of the query result desired

    Pedro Martins

    Maria Ana Marta

    Monica azenha

  • WHERE CHARINDEX(' ',ColumnName) > 0 is one way.

    WHERE ColumnName LIKE '% %' is another;

    you can also count the number of spaces and use that as criteria:

    WHERE DATALENGTH(ColumnName ) - DATALENGTH(REPLACE(ColumnName,' ','') > 0

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • WHERE ColumnName LIKE '% %' is another;

    Thank you

  • what about numbers?

    I don't want that names having number appear in the query results pan.

    i.e - Pedro2

    Pedro

    Only want Pedro

  • WHERE ColumnName NOT LIKE '%[0-9]%'

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply