create function fmerg (@id int) returns varchar (8000) asbegindeclare @str varchar (8000) set @str = '' select @ str = @ str ',' short_name from v_person where psn_code = @ idset @ str = right (@ Str, LEN (@STR) -1) Return (@str) endGO
- Call the custom function Get the result Select Distinct PSN_CODE, DBO.FMERG (PSN_CODE) from V_Person