question

ramadonking avatar image
ramadonking asked

delimit square brackets in sql 2008

Hi I am having one small doubt how can i delimit square brackets or angular brackets in sql server 2008.. Below is my example Suppose I am having a string like '[52,14_hassubfolder],[25,3_hassubfolder],[25,14]' I want to split angular brackets such that the output should look like 52,14_hassubfolder in 1st row 25,3_hassubfolder in second row 25,14 in 3rd row. Please help
sql-server-2008delimited-string
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

dvroman avatar image dvroman commented ·
I'm having a hard time decoding what you're asking. It appears that your square brackets are "[]", but I don't know what your angular brackets are. There are parenthesis "()", brackets "[]" and braces "{}" which can be used for different things in SQL.
0 Likes 0 ·
ramadonking avatar image ramadonking commented ·
sorry, I want to remove square brackets in sql server 2008 from the given string
0 Likes 0 ·

1 Answer

·
KenJ avatar image
KenJ answered
My favorite resource for delimited lists in t-sql is the "Arrays and Lists in SQL Server" articles by Erland Sommarskog - [ http://sommarskog.se/arrays-in-sql.html][1]. It basically comes down to using a numbers/tally table to parse the string using "],[" as a delimiter and removing the trailing ] and leading [ - maybe even wrapping it up in a helper UDF so you can use it again wherever you might need it. The problem has been covered numerous times on this site. Here are a couple previous questions/answers that may get you going: [ http://ask.sqlservercentral.com/questions/90968/how-do-i-extract-data-from-a-variable-length-delim.html][2] [ http://ask.sqlservercentral.com/questions/23117/how-has-splitting-a-delimited-string-improved-sinc.html][3] "delimited-string" even has its own tag if you'd like to see more: [ http://ask.sqlservercentral.com/questions/topics/delimited-string.html?sort=active&pageSize=50][4] [1]: http://sommarskog.se/arrays-in-sql.html [2]: http://ask.sqlservercentral.com/questions/90968/how-do-i-extract-data-from-a-variable-length-delim.html [3]: http://ask.sqlservercentral.com/questions/23117/how-has-splitting-a-delimited-string-improved-sinc.html [4]: http://ask.sqlservercentral.com/questions/topics/delimited-string.html?sort=active&pageSize=50
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.