2010-01-21 95 views
1

我有一個這樣的字符串「10 *貓* 123456; 12 *大鼠* 789; 15 *馬* 365」我想分裂它像那樣的「貓,老鼠,馬」我做了此功能Sql分割函數

CREATE FUNCTION [dbo].[Split](@BenNames VARCHAR(2000)) 
RETURNS VARCHAR(2000) 
AS 
BEGIN 
    DECLARE @tmp VARCHAR(2000) 
    SET @tmp = @BenNames  
    SET @tmp = SUBSTRING(
      SUBSTRING(@tmp, CHARINDEX('*', @tmp) + 1, LEN(@tmp)), 
      0, 
      CHARINDEX('*', SUBSTRING(@tmp, CHARINDEX('*', @tmp) + 1, LEN(@tmp))) 
     ) 
    RETURN @tmp but it only split only one part "10*cat*123456" 

我想通過另一種功能或其他德路

回答