all groups > sql server programming > december 2005 >
You're in the

sql server programming

group:

Removing all between [ and ]


Re: Removing all between [ and ] Trey Walpole
12/14/2005 5:02:33 PM
sql server programming:
lookup charindex() and substring() in bol

[quoted text, click to view]
Re: Removing all between [ and ] Robbe Morris [C# MVP]
12/14/2005 7:15:09 PM
If you are using SQL Server 2005, you could do this with
a .NET UDF and Regular Expressions:

http://www.eggheadcafe.com/articles/sql_server_2005_clr_regex.asp

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.eggheadcafe.com/forums/merit.asp





[quoted text, click to view]

Removing all between [ and ] Simon Harris
12/14/2005 10:48:29 PM
Hi All,

Does anyone know of a way of removing everything between, and including two
given characters in string using TSQL.

e.g. If my result set returns 'Sample Text [12345]' where 12345 is unknown
text, how can I make this 'Sample Text'

I know this is something perhaps best done at application level, but in this
case I need to do this in the data, before it reaches the app.

Thanks!
Simon.

RE: Removing all between [ and ] Manish Sukhija
12/15/2005 12:00:03 AM
hi Simon,
Try this out
select substring('Sample Text[12345]',1,charindex('[','Sample
Text[12345]',1)-1) as Result

[quoted text, click to view]
Re: Removing all between [ and ] jsfromynr
12/15/2005 4:01:39 AM
Hi Simon ,
What Manish asked will work but fails for data without any '['
Try This
Select Substring('sample text [12345]', 1, Case When
CharIndex('[','sample text [12345]') > 0 Then CharIndex('[','sample
text [12345]') - 1 Else Len('sample text [12345]') End )

With Warm regards
Jatinder Singh
Re: Removing all between [ and ] Simon Harris
12/17/2005 9:52:30 AM
Jatinder, your timing could not have been better....I've been trying to work
out what was wrong!! :)

Thanks!!...and to the other guys that replied.

Simon.

[quoted text, click to view]

AddThis Social Bookmark Button