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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Using "LIKE" to compare

Author  Topic 

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2012-02-20 : 12:20:07
I've been using the following to make flat-out full comparisons of data between two tables.
SELECT ECSOID, personid, t1.FName, t1.Lname, t1.Mname, t1.hair, t1.eyes, t1.race, t1.RaceID, t1.EyeColorID, t1.HairColorID
FROM douglas.dbo.persondata t1
Inner JOIN DouglasMNI.dbo.mni t2
ON t1.FNAME = t2.FNAME
AND T1.MNAME = T2.MNAME
AND T1.LNAME = T2.LNAME
AND t1.dob = t2.dob
AND t1.hair=t2.HAIR
AND t1.race=t2.RACE
ORDER BY t2.ecsoid

However, now i need to do the same, but, with FNAME, LNAME, and MNAME, i need to find values that have only the first three characters matching in those fields, and the full values in the others. I know i need to use LIKE instead of "=", but am unfamiliar with the syntax for such. Any help is appreciated.

thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-20 : 12:30:35
LIKE will not look for specified set of letters but it will look for pattern. so you might be better off using this

SELECT ECSOID, personid, t1.FName, t1.Lname, t1.Mname, t1.hair, t1.eyes, t1.race, t1.RaceID, t1.EyeColorID, t1.HairColorID
FROM douglas.dbo.persondata t1
Inner JOIN DouglasMNI.dbo.mni t2
ON LEFT(t1.FNAME,3) = LEFT(t2.FNAME,3)
AND LEFT(T1.MNAME,3) = LEFT(T2.MNAME,3)
AND LEFT(T1.LNAME,3) = LEFT(T2.LNAME,3)
AND t1.dob = t2.dob
AND t1.hair=t2.HAIR
AND t1.race=t2.RACE
ORDER BY t2.ecsoid


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2012-02-20 : 12:41:26
Thank you.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-20 : 13:29:04
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -