Is it possible to call a function inside a SQL Server 2005 function

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 another function I'm trying to call.

I get an error, can we cause or is there a syntax problem?

Msg 156, level 15, state 1, procedure getEmployeeID, line 6
Invalid syntax next to the keyword "select".
Msg 102, level 15, state 1, procedure getEmployeeID, line 6
Invalid syntax next to ')'.

Thanks Prince

+5
source share
2 answers

If a [dbo].[gtEmployeeName]scalar returns, you're probably looking

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 the table you're probably 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

, , . join condition ( , gtEmployeeName EmployeeID .

+6

.

, .

? , - .

+3

All Articles