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.
Author |
Topic |
Pasi
Posting Yak Master
166 Posts |
Posted - 2014-07-30 : 11:37:50
|
HI all,I need help to query the dB to see if the first_name and last_name exist? Below is what I am trying to do but not sure how to construct and check for first and last name if exist?Thanks!The first and last name is in table called "person" and I am joining them into ngweb_bulk_enrollment table.SELECT user_name,password,b.first_name,b.last_name from ngweb_bulk_enrollments a INNER JOIN person b ON b.person_id = a.person_id |
|
ITTrucker
Yak Posting Veteran
64 Posts |
Posted - 2014-07-30 : 12:10:00
|
The statement below should show the names in bulk_enrollments that do not have a match in person. Change the IS NULL to IS NOT NULL to show all the names that do match to person. select user_name,password,b.first_name,b.last_name from ngweb_bulk_enrollments a left outer join person b on b.person_id = a.person_idwhere b.id IS NULLCould probably get fancy with a CASE statement and add a new column to let you know if they exist or not:select user_name,password,b.first_name,b.last_name, 'Exists' = CASE WHEN b.id IS NULL then 'NO' ELSE 'YES' ENDfrom ngweb_bulk_enrollments a left outer join person b on b.person_id = a.person_id |
|
|
Pasi
Posting Yak Master
166 Posts |
Posted - 2014-07-30 : 12:30:25
|
Thanks a lot! I will try it...quote: Originally posted by ITTrucker The statement below should show the names in bulk_enrollments that do not have a match in person. Change the IS NULL to IS NOT NULL to show all the names that do match to person. select user_name,password,b.first_name,b.last_name from ngweb_bulk_enrollments a left outer join person b on b.person_id = a.person_idwhere b.id IS NULLCould probably get fancy with a CASE statement and add a new column to let you know if they exist or not:select user_name,password,b.first_name,b.last_name, 'Exists' = CASE WHEN b.id IS NULL then 'NO' ELSE 'YES' ENDfrom ngweb_bulk_enrollments a left outer join person b on b.person_id = a.person_id
|
|
|
Pasi
Posting Yak Master
166 Posts |
Posted - 2014-07-30 : 18:40:46
|
ITTrucker, it works fine thank you!quote: Originally posted by ITTrucker The statement below should show the names in bulk_enrollments that do not have a match in person. Change the IS NULL to IS NOT NULL to show all the names that do match to person. select user_name,password,b.first_name,b.last_name from ngweb_bulk_enrollments a left outer join person b on b.person_id = a.person_idwhere b.id IS NULLCould probably get fancy with a CASE statement and add a new column to let you know if they exist or not:select user_name,password,b.first_name,b.last_name, 'Exists' = CASE WHEN b.id IS NULL then 'NO' ELSE 'YES' ENDfrom ngweb_bulk_enrollments a left outer join person b on b.person_id = a.person_id
|
|
|
|
|
|
|
|