Solved

SQL Query

Posted on 2011-09-23
7
324 Views
Last Modified: 2012-05-12
Ok i posted earlier a similar question but soon realised i need more help so here goes.

Trying to get certain types of text out of a memo column in my table, each memo feild will have similar data to below the only difference would be character lengths.

With reference to maales Spec: 102-004440 - issue 4
Notes of Spec
Export Licence No. 0123456789

Line Item 4
maales Part no. 206-058943-t4338-0026 002
Part Revision No:  002

Foreign End User:  The State of the Netherlands, ODC "Het Arsenaal", Rijkszee-en Marinehaven, 1781 ZZ Den Helder, The Netherlands
Manufacturer of Commodity:  hicrosemin Lovell

Ok what i need is any information after where it says Foreign end User: but only up to the comma, so in this case "The State of the Netherlands" in a seperate column.

and also in another column any thing after the comma so in this case "ODC "Het Arsenaal", Rijkszee-en Marinehaven, 1781 ZZ Den Helder, The Netherlands" but not including where it starts to say "Manufacturer of Commodity" the characters will be different in all cases.

my current view looks like this

SELECT     TOP (100) PERCENT dbo.ihead.ih_sorder, SUBSTRING(dbo.itran.it_memo, CHARINDEX('No.', dbo.itran.it_memo)+4,9)As ExportNo, dbo.itran.it_anal,
dbo.itran.it_stock, dbo.itran.it_quan, dbo.itran.it_dtedelv,dbo.itran.it_memo
FROM         dbo.ihead LEFT OUTER JOIN
                      dbo.itran ON dbo.ihead.ih_doc = dbo.itran.it_doc
WHERE     (dbo.itran.it_memo LIKE '%Foreign End User%') AND (dbo.ihead.ih_sorder = 'ORD15686') AND (dbo.itran.it_status = 'a') AND (dbo.itran.it_recno = '3')
ORDER BY dbo.itran.it_recno

John
0
Comment
Question by:pepps11976
  • 4
  • 3
7 Comments
 
LVL 6

Expert Comment

by:MuffyBunny
ID: 36587495
What types? Can you tell us an example of a specific piece of data you would want to extract from all of that?

Just out of curiosity, why the huge memo instead of individual columns per piece of info?
0
 

Author Comment

by:pepps11976
ID: 36587535
The huge memo its just the way our system works we do not have the ability to add columns

i did state in the above post what i need to extract sorry if it was unclear, from this peice

Foreign End User:  The State of the Netherlands, ODC "Het Arsenaal", Rijkszee-en Marinehaven, 1781 ZZ Den Helder, The Netherlands
Manufacturer of Commodity:  hicrosemin Lovell

i need everything after Foreign End User but no furthrt than the comm ie "The State of the Netherlands"

that needs to be in one column and lastly i need everything after the comma but to stop where it starts Manufacturer ie "ODC "Het Arsenaal", Rijkszee-en Marinehaven, 1781 ZZ Den Helder, The Netherlands"

hope this helps

john
0
 
LVL 6

Expert Comment

by:MuffyBunny
ID: 36587632
My bad. I missed the section where you said what you need.

Is that always the format? 'Foreign End User:' with 2 spaces?
Then the actual address always followed by 'Manufacturer of Commodity'?
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

Author Comment

by:pepps11976
ID: 36587635
Yes it can be
0
 
LVL 6

Accepted Solution

by:
MuffyBunny earned 500 total points
ID: 36587726
I created a table named memotest with 1 column named bigmemo. I populated it with the data sample you provided. Assuming the data always follows at least a semi-consistent format, something like this will do it:

SELECT SUBSTRING(bigmemo, CHARINDEX('Foreign End User: ', bigmemo) + 19, (CHARINDEX(',', bigmemo) - CHARINDEX('Foreign End User: ', bigmemo) - 19)) as col1, 
	SUBSTRING(bigmemo, CHARINDEX(',', bigmemo) + 2, (CHARINDEX('Manufacturer of', bigmemo) - CHARINDEX(',', bigmemo) - 3)) as col2
from memotest

Open in new window

0
 

Author Comment

by:pepps11976
ID: 36587848
Brilliant this seems perfect, One question will this allow for longer addresses and names etc
0
 
LVL 6

Expert Comment

by:MuffyBunny
ID: 36587977
as long as it follows the format of 'Foreign End User:  ' column1 data ',' column2 data 'Manufacturer of' the number of characters in the data is irrelevant.

Where you could run into problems would be if the column1 data actually has a comma in it. For example 'someplace,someplacebigger' . If that happens, 'someplacebigger' will become part of colunn2 data. If you're confident that wont happen, it's all good.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now