Google Mobile Ads

Wednesday, April 17, 2013

SQL'de Split Fonksiyonu


SQL'de Split Fonksiyonu

ALTER FUNCTION [dbo].[fn_Split](@text varchar(8000), @delimiter varchar(20) = ' ')
RETURNS @Strings TABLE
(
  Split VarChar(1000)
)
AS
BEGIN
DECLARE @index int
SET @index = -1
WHILE (LEN(@text) > 0)
  BEGIN 
    SET @index = CHARINDEX(@delimiter , @text) 
    IF (@index = 0) AND (LEN(@text) > 0) 
      BEGIN  
        INSERT INTO @Strings VALUES (@text)
          BREAK 

      END 
    IF (@index > 1) 
      BEGIN  
        INSERT INTO @Strings VALUES (LEFT(@text, @index - 1))  
        SET @text = RIGHT(@text, (LEN(@text) - @index)) 
      END 
    ELSE
      SET @text = RIGHT(@text, (LEN(@text) - @index))
    END
  RETURN
END

Kullanımı:

SELECT Split FROM [dbo].[fn_Split] ('EUR,TRY,JPY', ',')






SQL Split Function

No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...