Correct syntax for string comparison in SQL?
Hello
Sorry I think I may have asked this question in the past but now this has become a comedy of errors.
Simply put, there are two tables in the same DB containing rows of individuals last names, first, DOB etc,
Table 1 has 3000 records
Table 2 has 4000 in which the above 3000 are intermingled with no other matching identity except last name.
I need the query to pull out the 1000 names that were added.
No success yet on several approaches. Last names are nvarchar max, SQL Server.
<cfquery name="find_added_lastnames" datasource="#Request.BaseDSN#">
Select lastname1
from TABLE1
join TABLE2
on ' '+ lastname1+' ' not like '% '+ lastname2+' %'
ORDER BY lastname2 ASC
<cfquery name="find_added_lastnames" datasource="#Request.BaseDSN#">
SELECT lastname1, lastname2
FROM table1, table2
WHERE lastname1 NOT LIKE '%lastname2%'
ORDER BY lastname2 ASC
</cfquery>
<cfquery name="find_added_lastnames" datasource="#Request.BaseDSN#">
SELECT lastname1, lastname2
FROM table1, table2
WHERE lastname1 NOT LIKE lastname2 + '%'
ORDER BY lastname2 ASC
</cfquery>
Actually running the above query works with “LIKE” vs “NOT LIKE” returns- New Last Names: 14388 (cartesian product).
Plus several iterations of these.
Any help much appreciated.
Thank You- Norman B.
