Question
What I Have so far: CREATE FUNCTION fnInsPlans (@PlanName varchar(50)) RETURNS int BEGIN RETURN (SELECT COUNT(*) FROM EmpData WHERE TermDate IS NOT NULL (SELECT BenPlanID
What I Have so far: CREATE FUNCTION fnInsPlans (@PlanName varchar(50)) RETURNS int BEGIN RETURN (SELECT COUNT(*) FROM EmpData WHERE TermDate IS NOT NULL (SELECT BenPlanID FROM Benefits WHERE PlanName = @PlanName)) END;
Instructions: The return portion of the select should include one column- a count of the records in the EmpData table and should filter the results so only active employees (not terminated) are counted. The where should also utilize a subquery in the where to find the BenPlanID number based on the input parameter (@PlanName).
I am struggling with getting my subquery to work, currently it just says "Select statements included within a function cannot return data to a client". What would be the correct way to put this in order for it to work properly?
This is for SQL Server NOT MySQL
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started