SQL 服务器函数如何在查询中使用参数

SQL server function how to use parameter to in query

我的 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

试试这个:

    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