Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 SQL Server 6.5 \ SQL Server 7.0
 Query Question

Author  Topic 

whr2
Starting Member

9 Posts

Posted - 2009-04-17 : 10:17:42
I have a field that is being returned in a query that could contain information that looks like this:


\FLAG=ADR

or

machine \FLAG=PPS10

or

machine \FLAG=DONOTHING unknown


The information after \FLAG= could be almost anything. I'm trying to figure out how to strip out everything and just have the information after \FLAG=. So in my examples I above I would see this returned:

ADR
PPS10
DONOTHING

Suggestions?

Thanks

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2009-04-17 : 10:28:27
declare @t table( mydata varchar(255))

insert into @t
select '\FLAG=ADR' union all
select 'machine \FLAG=PPS10' union all
select 'machine \FLAG=DONOTHING unknown'

select * from @t

select substring(mydata, charindex('\FLAG=', mydata, 1)+len('\FLAG='), len(mydata)) from @t


"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-17 : 10:28:47
select substring(col,charindex('\FLAG=',col)+6,len(col)) from your_table


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-17 : 10:29:54


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

whr2
Starting Member

9 Posts

Posted - 2009-04-17 : 10:46:12
quote:
Originally posted by madhivanan

select substring(col,charindex('\FLAG=',col)+6,len(col)) from your_table


Thanks, those got me in the ballpark. In my example I'm seeing this where machine \FLAG=DONOTHING unknown, I get a result return of DONOTHING unknown, but I think I can figure that out.
Go to Top of Page
   

- Advertisement -