ALTER function [dbo].[getEmployeeID](@ID int) returns table
as
begin
return (
select * from [dbo].[gtEmployeeName](2)
select * from Employees where EmployeeID = @ID)
end
here [dbo].[gtEmployeeName]
is an other function that I am trying to call.
I am getting an error, can we call or is there any syntax problem?
Msg 156, Level 15, State 1, Procedure getEmployeeID, Line 6
Incorrect syntax near the keyword 'select'.
Msg 102, Level 15, State 1, Procedure getEmployeeID, Line 6
Incorrect syntax near ')'.
Thanks Prince
Calling a function from within itself is called recursion and the simple answer is, yes.
When calling a function from a SELECT statement, that function can only perform DML (insert, update, delete) statements if it is defined as an AUTONOMOUS_TRANSACTION. 2. You should avoid using RESULT_CACHE with temporary tables. The PL/SQL documentation even presents this as a restriction.
A procedure cannot be called by a function. DML statments cannot be executed within a function. DML statements can be executed within a procedure.
If [dbo].[gtEmployeeName]
returns scalar you probably are looking for
ALTER function [dbo].[getEmployeeID](@ID int) returns table
as
begin
return (
select *, [dbo].[gtEmployeeName](2) as EmpName from Employees where EmployeeID=@ID)
end
If [dbo].[gtEmployeeName]
returns table you probably are looking for
ALTER function [dbo].[getEmployeeID](@ID int) returns table
as
begin
return (
select * from [dbo].[gtEmployeeName](2) EN
inner join Employees E on EN.EmployeeID = E.EmployeeID
where EmployeeID=@ID)
end
Update the join to outer if that is what you need. Also update the join condition
(the example assumes that the returned table from gtEmployeeName
has a column EmployeeID
and that can be used for joining to Employees.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With