首頁  >  文章  >  資料庫  >  SQL多行字符串按条件合并_MySQL

SQL多行字符串按条件合并_MySQL

WBOY
WBOY原創
2016-05-27 19:11:451349瀏覽

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 = &#39;&#39;
-- Add the T-SQL statements to compute the return value here
SELECT @ReturnValue=@ReturnValue + RTRIM(LTRIM(c.PartName)) + &#39;,&#39;
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

 

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn