Solved

SQL Query

Posted on 2011-09-23
7
323 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:pepps11976
Comment Utility
Yes it can be
0
 
LVL 6

Accepted Solution

by:
MuffyBunny earned 500 total points
Comment Utility
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
Comment Utility
Brilliant this seems perfect, One question will this allow for longer addresses and names etc
0
 
LVL 6

Expert Comment

by:MuffyBunny
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 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

11 Experts available now in Live!

Get 1:1 Help Now