分享

SQL分割字符串函数

 kittywei 2011-03-14
 --SQL分割字符串函数的调用查询语句
--输出结果为数据表
Declare @strPrimaryKey nvarchar(500)
set @strPrimaryKey='1,2,3,4,5,6,7'
Declare @strPlitChar nvarchar(10)
set @strPlitChar=','
Declare @strReturn nvarchar(500)
select * from  dbo.fun_SplitStr(@strPrimaryKey,@strPlitChar)
--SQL分割字符串函数
CREATE FUNCTION dbo.fun_get_SplitStr
(
 @SourceSql    varchar(8000),
 @StrSeprate    varchar(100))
 returns @temp   table(F1 varchar(100)
)  
AS    
BEGIN  
  declare ch   as    varchar(100)  
  set     @SourceSql =@SourceSql+@StrSeprate    
  while(@SourceSql<>'')  
  BEGIN
        set      @ch=left(@SourceSql,charindex(',',@SourceSql,1)-1)  
   insert   @temp   values(@ch)  
   set      @SourceSql=stuff(@SourceSql,1,charindex(',',@SourceSql,1),'')  
  END  
  return  
END
 
本篇文章来源于:开发学院 http://edu.   原文链接:http://edu./2011/0304/29775.php

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多