SQL Server函数如何在查询中使用参数

时间:2019-07-18 12:24:46

标签: sql-server sql-function

我的sql函数不是工作参数值。如果提供硬代码值,它将给我结果。

ALTER function [dbo].[team_concat] (@input varchar)
returns varchar(8000)
as
BEGIN
declare @putout varchar(8000)
set @putout = null

-- select @putout = COALESCE(IsNull(@putout+ ', ', ''), '') + team_residence_location from programs where team_combo = 'Hartford CIS / Coaching'
select @putout = COALESCE(IsNull(@putout+ ', ', ''), '') + team_residence_location from programs where team_combo = @input


return @putout

1 个答案:

答案 0 :(得分:1)

尝试一下:

    ALTER function [dbo].[team_concat] (@input varchar(100))  --- specify length
    returns varchar(8000)
    as
    BEGIN
    declare @putout varchar(8000)
    set @putout = null

    -- select @putout = COALESCE(IsNull(@putout+ ', ', ''), '') + team_residence_location from programs where team_combo = 'Hartford CIS / Coaching'
    select @putout = COALESCE(IsNull(@putout+ ', ', ''), '') + team_residence_location from programs where team_combo = @input


    return @putout