无法执行此功能,我收到错误:
必须声明表变量“@Handle”。
功能定义:
CREATE FUNCTION [dbo].[FnGetHandle]()
RETURNS INT
AS
BEGIN
DECLARE @Handle AS INT;
DECLARE @strUser AS NCHAR(256);
SET @Handle = 0;
SET @strUser = CURRENT_USER;
INSERT INTO tbl_handle
Output Handle
INTO @Handle ( UserName )
VALUES ( @strUser );
RETURN @Handle
END
表格定义:
tbl_handle definition(Handle int identity,username nvarchar,created 日期)
答案 0 :(得分:3)
output
命令输出到表或表变量。您可以创建一个保存输出值的表变量。
declare @T table(handle int)
insert into ...
select ...
output inserted.Handle into @T
select @Handle = handle
from @T
return @Handle