代码改变世界

串联所有符合条件的行ID ----SQL 函数

2011-06-21 11:31  yuejianjun  阅读(220)  评论(0编辑  收藏  举报
USE [FastDB]
GO
/****** Object:  UserDefinedFunction [dbo].[FunDIS]    Script Date: 06/21/2011 11:28:57 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER FUNCTION  [dbo].[FunDIS](@id int ) 
RETURNS varchar(MAX)  
AS
begin 
 
  declare   @ret   varchar(MAX) 
         set   @ret= '' 
        select     @ret=@ret+ ','+ rtrim(DistrictID) 
        from   DistrictDirectory as dd   where    dd.id=@id  '
RETURN(@ret)
end