Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Remove set of characters between [abcd] in a variable


Remove set of characters between [abcd] in a variable

Author
Message
sammm
sammm
Grasshopper
Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)

Group: General Forum Members
Points: 17 Visits: 368
I have a SP which gets parameter @business like this

[abcdef] Client
[gdhdnuidd] 1st Party SW
testbusiness

I want to get rid of the charcters from [ and ]. Is there a SQL function which searches for the open bracket[ and closing bracket ] and remove the whole set of characters.

Is it possible. Appreciate your help on this,.

The end result i want should be like this

Client
1st Party SW
testbusiness


Basically i want to remove the characters inside the brackets and the bracket too..


--Sam
WayneS
WayneS
SSCertifiable
SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)

Group: General Forum Members
Points: 6241 Visits: 10403
How does this work?
declare @test table (Col1 varchar(50))
insert into @test
select '[abcdef] Client' UNION ALL
select '[gdhdnuidd] 1st Party SW' UNION ALL
select 'testbusiness'

select case when charindex(']', Col1) > 0 then substring(Col1, Charindex(']', Col1)+2, 50)
else Col1 end
from @test



Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
Links: For better assistance in answering your questions, How to ask a question, Performance Problems, Common date/time routines,
CROSS-TABS and PIVOT tables Part 1 & Part 2, Using APPLY Part 1 & Part 2, Splitting Delimited Strings

ColdCoffee
ColdCoffee
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2317 Visits: 5545
My 2 cents :-)


declare @table table(
string varchar(50)
)
insert @table (string)
select '[gdhdnuidd] 1st Party SW'
union all select '[abcdef] Client'
union all select 'testbusiness'

select
case
when charindex(']',string) > 0 then right (string, (len(string)- charindex(']',string)))
else string
end finalstring
from @table


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search