Stored procedure to return multiple records based on multiple conditions
I am new to SQL server, thus looking for some quick help on writing stored procedure:
brief about what I am doing: employee says he is expert (type) in different domains (industries) and willing to work in countries of choice (mycountries) and my sal (minsal)and my native country (orgcountry)
Employer says he need so and so expert in the his choice of domain (industries) in the countries where openings are there and with sal range.
employee table has lots of records with columns like this: name, email, myindustries, mycountries, mytype,minsal
employer table has lots of records with columns like: expertneed, inindustries, incountries, sal-from, sal-to
now when employee logs in, he/she should get all the records of matching employers
when employer logs in, he/she also get开发者_开发百科 all the records of matching employees.
can some one help in writing sp for this? appreciate any help
If you're storing comma-separated ids then you'll need a function to split a string into multiple rows. This is how you would use it:
SELECT DISTINCT employee.name [employee], employer.name [employer]
FROM employee
OUTER APPLY dbo.split(employee.myindustries) myi (industry)
OUTER APPLY dbo.split(employee.mycountries) myc (country)
JOIN employer
OUTER APPLY dbo.split(employer.inindustries) ini (industry)
OUTER APPLY dbo.split(employer.incountries) inc (country)
WHERE employer.expertneed = employee.type
AND ini.inindustries = myi.industry
AND inc.incountries = myc.country
AND employee.minsal BETWEEN employer.[sal-from] AND employer.[sal-to]
精彩评论