下面的函数返回一条记录而不是多条记录,这是Scalar-valued
我创建的一个函数......
ALTER FUNCTION [_SMDBA_].[ASSETTAG](@ticket int)
RETURNS VARCHAR(MAX)
AS
BEGIN
-- Declare the return variable here (asset#)
DECLARE @assettag VARCHAR(MAX)
-- Query to return all the tasset #s
SELECT @assettag = "Asset/Tag #"
FROM sde."_SMDBA_"."Inventory Items"
WHERE "Configuration ID" = (SELECT "Client ID"
FROM sde."_SMDBA_"."Incident"
WHERE "Incident #"=@ticket)
-- Return the result of the function
RETURN @assettag
END
知道如何返回多个结果吗?
@Andriy M 非常感谢!我对 tsql 还很陌生,所以我根据我的逻辑创建了这个函数!
我的函数的目的是显示列的分隔字符串值(请不要问我为什么),这是我的 finale 函数,目前工作正常,如果有什么需要改进和/或更改的,请告诉我:
ALTER FUNCTION [_SMDBA_].[ASSETTAG3](@ticket int)
RETURNS @result TABLE
(Asset# nvarchar(50))
AS
BEGIN
Declare @concat varchar(50)
set @concat=''
SELECT @concat=@concat + "Asset/Tag #" +' / ' from sde."_SMDBA_"."Inventory Items"
where "Configuration ID"=(select "Client ID" from "_SMDBA_"."Clients" where "Client Name"=(select "Req Full Name" from "_SMDBA_"."Incident" where "Incident #"=(@ticket)))
INSERT into @result
select @concat
RETURN
end;