INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

SQL command to extract text from a varchar(MAX) field based on spaces of text after a specific name

SQL command to extract text from a varchar(MAX) field based on spaces of text after a specific name

SQL command to extract text from a varchar(MAX) field based on spaces of text after a specific name

(OP)
I am trying to extract only the "0606100000" from below: What is the best way to accomplish this?

varchar field info: a:8:{s:15:"info_buyRequest";a:9:
{s:4:"uenc";s:116:"aHR0cDovL2IyYi5zdXR0bGUtc3RyYXVzLmNvbS9DL2NsZWFyY2hv
aWNlL3dlYjJwcmludC9lZGl0b3IvbG9hZC90eXBlL3Byb2R1Y3QvaWQvNDc0Lw,,";s:7:"
product";s:3:"474";s:15:"related_product";s:0:"";s:10:"product_id";s:3:
"474";s:17:"chili_document_id";s:36:"92026af7-455e-4ccc-a801-
186f4f6a56d2";s:3:"qty";s:3:"500";s:4:"type";s:7:"product";s:2:"id";s:3
:"474";s:7:"options";a:1:{i:154;s:11:"Susie Smith";}}s:7:"options";a:1:
{i:0;a:7:{s:5:"label";s:27:"Enter Name on Business
Card";s:5:"value";s:11:"Susie Smith";s:11:"print_value";s:11:"Susie
Smith";s:9:"option_id";s:3:"154";s:11:"option_type";s:5:"field";s:12:"o
ption_value";s:11:"Susie
Smith";s:11:"custom_view";b:0;}}s:17:"giftcard_lifetime";N;s:22:"giftca
rd_is_redeemable";i:0;s:23:"giftcard_email_template";N;s:13:"giftcard_t
ype";N;s:17:"document_id";s:36:"92026af7-455e-4ccc-a801-
186f4f6a56d2";s:17:"jurisdiction_code";s:10:"0606100000";}

RE: SQL command to extract text from a varchar(MAX) field based on spaces of text after a specific name

Is it ALWAYS last 10 characters before ";} at the end?

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.

RE: SQL command to extract text from a varchar(MAX) field based on spaces of text after a specific name

(OP)
No, just always after the "jurisdiction_Code" lable.

RE: SQL command to extract text from a varchar(MAX) field based on spaces of text after a specific name

Some assumptions and settings:
1. I have your string in a text file C:\TEMP\MyTextFile.txt
2. What you are looking for is placed after jurisdiction_Code plus 8 characters ";s:10:"
3. The portion of the text you are looking for is 10 characters long.

CODE

Dim s As String = ""
Dim s1 As String = "jurisdiction_Code"
Dim tr As IO.TextReader = New IO.StreamReader("C:\TEMP\MyTextFile.txt")
Dim intStart As Integer = 0

s = tr.ReadToEnd

intStart = Strings.InStr(UCase(s), UCase(s1)) + Strings.Len(s1) + 8

MessageBox.Show(Strings.Mid(s, intStart, 10)) 

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.

RE: SQL command to extract text from a varchar(MAX) field based on spaces of text after a specific name

(OP)
Is there a way to do it if the string is just a varchar(MAX) field in my database?

Thanks for all of your help!!

RE: SQL command to extract text from a varchar(MAX) field based on spaces of text after a specific name

I work with Oracle and I can write a simple Function (stored in the data base) where I can pass a parameter, do some logic like I did above, and return a result. Then I can use this Function anywhere I need it, like:

Select Some Field, MyFunction(SomeOtherField) As ABCD
From MyTable
Where ...

I know you can do the same in Access, SQL, etc.

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close