SQL 拆分字符串
Create function [dbo].[split] ( @SourceSql varchar(max), @StrSeprate varchar(10) ) returns @temp table(line varchar(max)) as begin declare @i int set @SourceSql = rtrim(ltrim(@SourceSql)) set @i = charindex(@StrSeprate,@SourceSql) while @i >= 1 begin if len(left(@SourceSql,@i-1))>0 begin insert @temp values(left(@SourceSql,@i-1)) end set @SourceSql=substring(@SourceSql,@i+len(@StrSeprate),len(@SourceSql)-@i) set @i=charindex(@StrSeprate,@SourceSql) end if @SourceSql <> '' insert @temp values(@SourceSql) return end -----测试 GO Select * From dbo.split('asd,f,gh,jk,l',',') DECLARE @C NVARCHAR(MAX) SELECT @C=OrderContent FROM dbo.Export WHERE intBobyInfoID=15538 SELECT line [content] FROM dbo.split( (SELECT top 1 OrderContent FROM dbo.Export) ,'*')