Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Select Smart query Expand / Collapse
Author
Message
Posted Tuesday, July 20, 2010 12:42 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, July 20, 2010 12:38 AM
Points: 3, Visits: 2
Hello All,


I looking for a very cleaver query

I have a field LastName and by users mystake there are some that is having to names over that

for E.g//
FisrtName Lastname
Rafael Narezzi
That is ok
My problem is that I want a select to search for all users that is like that

Fisrtname LastName
Rafael Rafael Narezzi

how could I do a select to get all users that have spaces between?
Thanks
Post #955314
Posted Tuesday, July 20, 2010 2:52 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Wednesday, July 23, 2014 10:31 AM
Points: 999, Visits: 13,473
you could do a charindex check for a blank space and make sure the number returned is greater than 0. Make sure you trim your input though incase you have white space.

I think you could also use like '% %' but that should probably be avoided for performance reasons

i would personally use charindex but would like to see what others say
Post #955377
Posted Tuesday, July 20, 2010 12:30 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 8:43 AM
Points: 7,042, Visits: 12,971
Here are two options you could use:
--check for first name used as the first part of the last name
SELECT *
FROM @tbl
WHERE LastName LIKE RTRIM(Fisrtname)+' %'

-- check for a space in LastName (might produce false results, e.g. for Pietro de la Rosa )
SELECT *
FROM @tbl
WHERE CHARINDEX(' ',LastName)>0





Lutz
A pessimist is an optimist with experience.

How to get fast answers to your question
How to post performance related questions
Links for Tally Table , Cross Tabs and Dynamic Cross Tabs , Delimited Split Function
Post #955827
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse