USE [ARTEA.MES]GO/****** Object: UserDefinedFunction [dbo].[UnionPart] Script Date: 11/18/2015 15:39:34 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- =============================================-- Author: <Author,,Name>-- Create date: <Create Date, ,>-- Description: <Description, ,>-- =============================================ALTER FUNCTION [dbo].[UnionPart](-- Add the parameters for the function here@OrderNo varchar(30))RETURNS [nvarchar](4000)ASBEGIN-- Declare the return variable hereDECLARE @ReturnValue [nvarchar](4000)SET @ReturnValue = ''-- Add the T-SQL statements to compute the return value hereSELECT @ReturnValue=@ReturnValue + RTRIM(LTRIM(c.PartName)) + ','FROM table1 c left join table2 d on d.OrderID=c.OrderIDWHERE d.OrderNO = @OrderNoSET @ReturnValue = substring(@ReturnValue,1,len(@ReturnValue)-1)RETURN @ReturnValueENDGO |