This is my query inside my stored procedure
DECLARE @branch uniqueidentifier
SELECT @branch = Branch_Id
FROM Student_Master
WHERE Student_Id = @studentid
SELECT
CompanyMaster.unique_id_company,
Job_College.College_Id,
Job_Branch.Branch_Id,
CompanyMaster.name,
Job_Master.Job_Post_Date, Job_Master.Job_Title,
Job_Master.Salary, Job_Master.Job_Location,
Department_Master.Department_Name
FROM
Job_Master
INNER JOIN
Company_Master ON Job_Master.Company_ID = CompanyMaster.unique_id_company
INNER JOIN
Department_Master ON Department_Master.Department_Id = Job_Master.Department_Id
INNER JOIN
Job_College ON Job_Master.Job_ID = Job_College.Job_Id
INNER JOIN
Job_Branch ON Job_Branch.Job_College_ID = Job_College.Job_College_ID
WHERE
Job_Branch.Branch_Id = @branch
Logically query is correct and is producing expected results if I pass value of @branch
directly to it (instead of using SELECT
query in the beginning) but with this method shown in code by populating value of @branch
with select query at the beginning, this query results 0 results although @branch
is receiving value from it.
Things I have tried
- Using SELECT query directly inside WHERE clause
- I have seen that PRINT @branch gives right output so it should work in WHERE clause but it is not working
Please help!! I am stuck for past many hours