SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


?? on parse a field


?? on parse a field

Author
Message
jbalbo
jbalbo
SSChasing Mays
SSChasing Mays (613 reputation)SSChasing Mays (613 reputation)SSChasing Mays (613 reputation)SSChasing Mays (613 reputation)SSChasing Mays (613 reputation)SSChasing Mays (613 reputation)SSChasing Mays (613 reputation)SSChasing Mays (613 reputation)

Group: General Forum Members
Points: 613 Visits: 668
Hi

I have a field with "Data"
similar to
"@@"@@T_001_Version = "v2009.01.13.1_1.7"@@T_002_ = "@@T_749_formstatus = "0"@@T_750_finalscorestatus = "Draft"@@M_752_ = "*Hx of AH, VH, and d....

Some of these values in the field are large I want to pull only whats in between @@T_750_finalscorestatus = and @@M_752

sorry forgot to mention sometime the field ends on @@T_750_finalscorestatus = "Draft" not being between two values and for that matter not always followed by @@M_752_

so I guess I'm looking for what follows @@T_750_finalscorestatus = " until the closing "

Thanks
Joe
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26171 Visits: 17539

I have a field with "Data"
similar to
"@@"@@T_001_Version = "v2009.01.13.1_1.7"@@T_002_ = "@@T_749_formstatus = "0"@@T_750_finalscorestatus = "Draft"@@M_752_ = "*Hx of AH, VH, and d....


You gave us some business rules but you also stated that each of these business rules has an exception. Also is the above supposed to represent one of the values?


declare @Data varchar(1000)
set @Data = ' "@@"@@T_001_Version = "v2009.01.13.1_1.7"@@T_002_ = "@@T_749_formstatus = "0"@@T_750_finalscorestatus = "Draft"@@M_752_ = "*Hx of AH, VH, and d....'




Some of these values in the field are large I want to pull only whats in between @@T_750_finalscorestatus = and @@M_752


Some of them are large and you want only a portion? What defines large?


sorry forgot to mention sometime the field ends on @@T_750_finalscorestatus = "Draft" not being between two values and for that matter not always followed by @@M_752_


HUH???


so I guess I'm looking for what follows @@T_750_finalscorestatus = " until the closing "


HUH???

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
gbritton1
gbritton1
SSChasing Mays
SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)

Group: General Forum Members
Points: 651 Visits: 864
Something like this might handle the example problem:


declare @t table (txt varchar(max))

insert into @t(txt) values
('"@@"@@T_001_Version = "v2009.01.13.1_1.7"@@T_002_ = "@@T_749_formstatus = "0"@@T_750_finalscorestatus = "Draft"@@M_752_ = "*Hx of AH, VH, and d....')

select substring(txt, ca1.strStart, ca2.strEnd-ca1.strStart-1)
from @t t
cross apply (select 28+patindex('%@@T_750_finalscorestatus = "%', txt) from @t) ca1(strStart)
cross apply (select ca1.StrStart+patindex('%"%', substring(txt, ca1.strStart, len(txt))) from @t) ca2(strEnd)


jbalbo
jbalbo
SSChasing Mays
SSChasing Mays (613 reputation)SSChasing Mays (613 reputation)SSChasing Mays (613 reputation)SSChasing Mays (613 reputation)SSChasing Mays (613 reputation)SSChasing Mays (613 reputation)SSChasing Mays (613 reputation)SSChasing Mays (613 reputation)

Group: General Forum Members
Points: 613 Visits: 668
Wow Sean, and I tried real hard on this one... LOL :-D

I guess size really doesn't matter..
what I need are the 5 characters following the string @@T_750_finalscorestatus = " that would be a constant in that field

for example

if its "@@T_750_finalscorestatus = "Draft" then I want .. Draft
if its "@@T_750_finalscorestatus = "Final" then I want .. Final
if its "@@T_750_finalscorestatus = "" then I want null

Thanks
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26171 Visits: 17539
jbalbo (4/17/2014)
Wow Sean, and I tried real hard on this one... LOL :-D

I guess size really doesn't matter..
what I need are the 5 characters following the string @@T_750_finalscorestatus = " that would be a constant in that field

for example

if its "@@T_750_finalscorestatus = "Draft" then I want .. Draft
if its "@@T_750_finalscorestatus = "Final" then I want .. Final
if its "@@T_750_finalscorestatus = "" then I want null

Thanks



hehe.

Maybe something like this is what you are after?


declare @Data varchar(1000)
set @Data = ' "@@"@@T_001_Version = "v2009.01.13.1_1.7"@@T_002_ = "@@T_749_formstatus = "0"@@T_750_finalscorestatus = "Draft"@@M_752_ = "*Hx of AH, VH, and d....'

select
case when charindex('@@T_750_finalscorestatus = "Draft"', @Data) > 0 then 'Draft'
when charindex('@@T_750_finalscorestatus = "Final"', @Data) > 0 then 'Final'
else NULL
end



_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
jbalbo
jbalbo
SSChasing Mays
SSChasing Mays (613 reputation)SSChasing Mays (613 reputation)SSChasing Mays (613 reputation)SSChasing Mays (613 reputation)SSChasing Mays (613 reputation)SSChasing Mays (613 reputation)SSChasing Mays (613 reputation)SSChasing Mays (613 reputation)

Group: General Forum Members
Points: 613 Visits: 668
Thanks worked great and I learned something new today Smile

CASE WHEN charindex('@T_750_finalscorestatus = "Draft"', Assessment_data) > 0 THEN 'Draft'
WHEN charindex('@T_750_finalscorestatus = "Final"', Assessment_data) > 0 THEN 'Final'
ELSE NULL END AS SigType
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26171 Visits: 17539
jbalbo (4/17/2014)
Thanks worked great and I learned something new today Smile

CASE WHEN charindex('@T_750_finalscorestatus = "Draft"', Assessment_data) > 0 THEN 'Draft'
WHEN charindex('@T_750_finalscorestatus = "Final"', Assessment_data) > 0 THEN 'Final'
ELSE NULL END AS SigType


Cool. Glad that worked for you. You can leave the ELSE off if you want. When a case expression does not find a path it will return NULL.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
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