Split string in SQL Server

Posted by Naraayanan under Sql Server on 5/3/2013 | Points: 10 | Views : 1320 | Status : [Member] | Replies : 2
Hi all,

This is my query for split a string for Particular Column and Table. i want this query in function ,It should be dynamic, that means user can declare a column Name, delimiter and Table Name . this function will use in the my Select Query (like Avg(), Min(),Max() function)so Please let me know if you ideas and Answers.

Query
    Select RIGHT(DCNO,LEN(DCNO)-CHARINDEX('C',DCNO))  from tbl_dc


Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/



Responses

Posted by: Somasundaram on: 5/3/2013 [Member] Starter | Points: 25

Up
0
Down
Hi.,


DECLARE @Query nvarchar(1000),@columnName varchar(100),@delimiter varchar(10)
SET @columnName = 'name'
SET @delimiter = 'C'

SET @Query = ' Select RIGHT( ' + @columnName + ' ,LEN( ' + @columnName + ' )-CHARINDEX( ''' + @delimiter + ''' , ' + @columnName + ' )) from tbl_dc '


I think this will help you.

Regards,
Somasundaram

Naraayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Niladri.Biswas on: 5/6/2013 [Member] Platinum | Points: 25

Up
0
Down
Check out these two links.I wrote it some times back.This will surely help you

http://www.dotnetfunda.com/codes/code1797-split-function-in-sql-server-using-set-base-approach.aspx

http://www.dotnetfunda.com/codes/code1796-split-a-set-of-contiguous-string-into-individual-charactersletters-us.aspx

Best Regards,
Niladri Biswas

Naraayanan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response