I am working one something and I can’t get it to work. I am trying to Create a user defined function named Employee_Name. Pass an Employee Id as a parameter.Return the First Name, Last Name, and Phone Number of the employee whose ID matches the id passed to the user defined function.Create a query that uses the function and returns information for the employee with an id of 5. But In order to finish the function employee name I can not get it to work. I keep getting this error:
Msg 207, Level 16, State 1, Procedure Employee_Name, Line 10
Invalid column name 'Employee_Name'.
Msg 208, Level 16, State 1, Line 2
Invalid object name 'Employee_name'.
The code looks like this:
CREATE FUNCTION Employee_Name
(
@EmployeeID int
)
RETURNS TABLE
AS
RETURN
(
SELECT * FROM Employees
WHERE Employee_Name = @EmployeeId
)
GO
SELECT * FROM Employee_name (1)
Now to get the Return on First name,lastname and phone wouldnt I so a select on the employees id where it goes like this
Select
FirstName,
LastName,
PhoneNumber
From EmployeeId
Or something like that.Now to get the employee with and Id of 5 would i use the count or do something that has an =5; I am not to sure still confused.
Edit: This is what I have again:
CREATE FUNCTION Employee_Name
(
@EmployeeID int
)
RETURNS TABLE
AS
RETURN
(
SELECT FirstName,LastName,HomePhone
FROM Employees
WHERE Employee_Name = @EmployeeId
)
GO
This line:
does not make sense. Surely you mean something like
?
And this query:
should surely be this:
?