我與SQL Server 2012的如何執行正在返回表的用戶定義函數sql?
我已經創造了SQL函數像這樣的工作:
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 [email protected] and UL.LocationType='COMPANY'
RETURN
END
我不知道它的正確的方式與否。
現在我試圖執行這樣的功能:
DECLARE @ret as table (UserId int null)
EXEC @ret = [dbo].[Fn_IsCompanyExistInUserLocation] @CompanyId= 10;
select UserId from @ret
和我收到的錯誤:
Msg 137, Level 16, State 1, Line 6
Must declare the scalar variable "@ret".
你不需要告訴我們,例如你會標記出接受的答案。這就是SO *如何工作*。 –
ooohhh really;) –