Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Remove set of characters between [abcd] in a variable Expand / Collapse
Author
Message
Posted Monday, June 28, 2010 7:13 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, December 2, 2013 10:18 AM
Points: 17, Visits: 326
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
Post #944345
Posted Monday, June 28, 2010 10:13 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:57 PM
Points: 5,358, Visits: 8,916
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
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
Post #944368
Posted Monday, June 28, 2010 10:59 PM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, September 12, 2014 5:21 PM
Points: 2,262, Visits: 5,406
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

Post #944376
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse