joblo37pam
2[H]4U
- Joined
- Jun 28, 2002
- Messages
- 2,211
I'm self-taught in SQL, so please forgive the crudeness of what I'm trying to do.
I manage an asp.net app with a MS SQL 2005 database that is used to enter event registrations for an organization I belong to. Each entry becomes a new row in the database, and that all works great. The only problem I'm having is building a report that does what i want it to. Some of the events require a partner, so when an entry for those events is made, the contestant is asked to enter their partner's name so that they can be matched together later. This is where the problem comes in.
Since the contestant's own name is separated into first and last name fields (ContFirstName, ContLastName), but they enter their partners name in a single field (PartnerName), it is difficult to programatically match the partners entries together. I have come up with a query that will basically do what I want as long as the contestant spells their own name the same way that their partner does, but am having a hard time trying to get the mispelled ones matched. Here is what I have:
I understood LEFT JOIN would return all of the columns in the left table, even if there isn't a match in the right table. That isn't happening for some reason. Currently, there are 38 entries in the table for a partner event, but this query only returns the 32 that are spelled correctly and ignores the rest. Even if I could get the query to return a null or empty string if it doesn't find a match, I could work with that in the asp code. I just can't seem to figure out why the left join isn't returning all of the rows.
Any help would be appreciated. If you need more information, just ask. Like I said, I'm a noob at this, so I'm not sure what I'm missing. Thanks.
I manage an asp.net app with a MS SQL 2005 database that is used to enter event registrations for an organization I belong to. Each entry becomes a new row in the database, and that all works great. The only problem I'm having is building a report that does what i want it to. Some of the events require a partner, so when an entry for those events is made, the contestant is asked to enter their partner's name so that they can be matched together later. This is where the problem comes in.
Since the contestant's own name is separated into first and last name fields (ContFirstName, ContLastName), but they enter their partners name in a single field (PartnerName), it is difficult to programatically match the partners entries together. I have come up with a query that will basically do what I want as long as the contestant spells their own name the same way that their partner does, but am having a hard time trying to get the mispelled ones matched. Here is what I have:
Code:
SELECT parent.PartnerName, child.FirstName + child.Lastname FROM Entries as parent LEFT JOIN Entries as child ON (rtrim(parent.partnername)) = (rtrim(child.FirstName) + ' ' + rtrim(child.LastName))
I understood LEFT JOIN would return all of the columns in the left table, even if there isn't a match in the right table. That isn't happening for some reason. Currently, there are 38 entries in the table for a partner event, but this query only returns the 32 that are spelled correctly and ignores the rest. Even if I could get the query to return a null or empty string if it doesn't find a match, I could work with that in the asp code. I just can't seem to figure out why the left join isn't returning all of the rows.
Any help would be appreciated. If you need more information, just ask. Like I said, I'm a noob at this, so I'm not sure what I'm missing. Thanks.