Monday, November 1, 2010

is it possible to join tables by multiple fields?

Programmer Question

The scenario is this. We have a customer table with all the logical customer information, and a different table we're going to call "event". In the event table, among other things, are the client's first name, last name, and ssn.



In the customer table, the ssn is a varchar(9) intended only for digits obviously, however the event table's ssn is varchar(11), intended for digits plus dashes. The thing is some of the clients could be people or entities, and the ssn is used to differenciate between the as such:



People's ssn format is 123-45-6789 while entities' format is 12-3456789.



So what I want to do is run a query that joins the Customer and Event tables on both the first names AND last names so that I can check for discrepancies in the formatting of SSN in the Event table.



I'm a relatively new developer so I've never been faced with this kind of situation and don't know if it were possible. Here's what my current query looks like:



SELECT top 10 c.firstname, c.lastname, c.ssn, e.ssn, e.firstname, e.lastname
FROM customer c with(nolock)
LEFT OUTER JOIN [event] e with(nolock) on
c.firstname = e.firstname and
c.lastname = e.lastname


Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails