当前位置:首页 > 数据库 > Sqlserver

SQL Server 【CTE + FOR XML PATH】使用笔记~

CREATE
 FUNCTION [dbo].[Getxxxxxxxxx]
    (
      @productCategoryId INT,
@SplitChar varchar ) RETURNS NVARCHAR(MAX) AS BEGIN DECLARE @returnProductCategory NVARCHAR(MAX)=N‘‘ /*-- 注意,CTE 表达式前面必须要用分号“;”把其代码分开,建议在WITH前面加分号“;” --*/ ;WITH cte AS ( SELECT ProductCategoryID FROM Tidebuy_SCM_Test.dbo.xxxx_xxxx parent(NOLOCK) WHERE ProductCategoryID=@productCategoryId UNION ALL SELECT child.ProductCategoryID FROM xxx_xxx child(NOLOCK) INNER JOIN cte ON child.ParentID=cte.ProductCategoryID ) SELECT @returnProductCategory = ( SELECT ( SELECT CAST(cte.ProductCategoryID AS NVARCHAR(10))+‘,‘ FROM cte FOR XML PATH(‘‘) ) AS temp ) RETURN @returnProductCategory END GO

原文:http://www.cnblogs.com/oceanho/p/5014837.html


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐