当前位置: 移动技术网 > IT编程>数据库>MSSQL > SQL多行字符串按条件合并

SQL多行字符串按条件合并

2018年03月03日  | 移动技术网IT编程  | 我要评论

a4纸打百元假钞,分形艺术照,陈滢巧

USE [ARTEA.MES]
GO

/****** Object: UserDefinedFunction [dbo].[UnionPart] Script Date: 11/18/2015 15:39:34 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- 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)
AS
BEGIN
-- Declare the return variable here
DECLARE @ReturnValue [nvarchar](4000)
SET @ReturnValue = ''
-- Add the T-SQL statements to compute the return value here
SELECT @ReturnValue=@ReturnValue + RTRIM(LTRIM(c.PartName)) + ','
FROM table1 c left join table2 d on d.OrderID=c.OrderID
WHERE d.OrderNO = @OrderNo
SET @ReturnValue = substring(@ReturnValue,1,len(@ReturnValue)-1)
RETURN @ReturnValue

END

GO

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网