i am working with SQL server 2012.
i have created a function in sql like this:
CREATE FUNCTION [dbo].[Fn_IsCompanyExistInUserLocation](@CompanyId int)
RETURNS @Result table
(
UserId int null
)
AS
BEGIN
insert into @Result(UserId) select UL.UserId FROM [RRT_Reporting].[dbo].[UserLocation] as UL where UL.CompanyId=@CompanyId and UL.LocationType='COMPANY'
RETURN
END
i am not sure its right way or not.
now i am trying to execute this function like :
DECLARE @ret as table (UserId int null)
EXEC @ret = [dbo].[Fn_IsCompanyExistInUserLocation] @CompanyId= 10;
select UserId from @ret
and i am getting error:
Msg 137, Level 16, State 1, Line 6
Must declare the scalar variable "@ret".