I am trying to create a decision statement to determine if the 5 variables (@skill1, @skill2, @skill3, @skill4, @skill5) are not null or empty.
The people_skills table contains different skills for each person. So there may be more than 1 record for a person. The lkp_skills contains the names of those skills.
Based on the 5 different skill fields, I want to ignore the empty string. I also want to search for the strings within the lkp_skills table. If the variable matches the s.skill field of that table then i want it to return that record. If there are multiple skills then I want it to return records that have Both of those skills.
What is the best way of doing this?
DECLARE @zip char(5) = '61265', -- Zip Code
@skill1 varchar(50) = 'sql', -- Job Skill 1
@skill2 varchar(50) = 'css', -- Job Skill 2
@skill3 varchar(50) = '', -- Job Skill 3
@skill4 varchar(50) = '', -- Job Skill 4
@skill5 varchar(50) = '', -- Job Skill 5
@distance int = 5 -- Distance in miles
SELECT p.people_id, p.first_name, p.last_name, p.address_1, p.address_2, p.city, p.[state],
p.zip_code, (dbo.sp_getDistance(@zip, zip_code)) AS miles, s.skill
FROM people p
INNER JOIN people_skills ps ON ps.people_id = p.people_id
INNER JOIN lkp_skills s ON ps.skill_id = s.skill_id
WHERE (ISNUMERIC(p.zip_code) = 1 AND LEN(RTRIM(LTRIM(p.zip_code))) = 5)
AND p.ROLE_ID <= 4
AND ((dbo.sp_getDistance(@zip, zip_code)) <= @distance)
AND
-- DECISION STATEMENT GOES HERE --
ORDER BY miles