Image: screenshot of TextImport table
Use the correct operator for the job at hand
R E L A T E D   C O N T E N T
ADVERTISEMENT

Hands on: Importing text into Access

Import data as text strings into a database; plus why MVFs are a pain

Mark Whitehorn, Personal Computer World 28 Nov 2006
ADVERTISEMENT

Brian Ritchie has some data he wants to import into an SQL-type database, such as Access or Oracle. The data comes from an old mainframe system and started as a comment field. However, the only way Brian can export the data is as a series of text strings. His question is whether it is possible to stitch these back together again into, say, a memo field in Access.

No problem. The first step is to import the table containing the text strings into a table in Access. Now use an UPDATE query using GUI. First, open the query builder in design view and add the table TextImport. Pop down the Query menu option and choose Update Query. Select the field called AllText and then type the following into the Update To section:

[T1] & “ “ & [T2] & “ “ & [T3] & “ “ & [T4]

This says, essentially, add the contents of the T1 field to a space and then add the contents of the field called T2, then add a space, and so on and so forth.This is saved as a query called FixText. When you run it you will see two warning messages; accept those and it will run and update the AllText column. The SQL is:

UPDATE TextImport SET TextImport.AllText = [T1] & “ “ & [T2] & “ “ & [T3] & “ “ & [T4];

This process of stringing values together is called concatenation and the & operator is, unsurprisingly, a concatenation operator. You can also use + as a concatenation operator, but it has an odd side-effect.

If any of the strings being concatenated is null or zero-length, then the entire string becomes null. You can see this effect by running the query called FixText2, which uses + instead of &. After running, the second row of the AllText field is blank because of the null value in T4.

This is not a bug as there are circumstances in which it is desirable to have the entire field as a null if even one component is null. The trick is, of course, to use the correct operator for the job in hand.


All Software Applications
Tags: Databases

Like this story? Spread the news by clicking below:

Post this to Delicious del.icio.us    Post this to Digg Digg this    Post this to reddit reddit!

Permalink for this story
R E A D E R   C O M M E N T S
M A R K E T P L A C E
Get your free demo of Numara Track-It! 8 - the leading help desk solution for IT related issues.
Make presentations, review documents & share your entire desktop. 30-day free trial! (cc required).
Discover how remote support can fuel your IT business in ways you've never thought of before.
Apply ITIL best practices at your service desk while eliminating integration cost. Learn more here.
WAN based, automated, daily vulnerability assessments. Click here to try and request our whitepapers.
Have your product or service listed here >   
Sponsored links
F E A T U R E D   J O B S
Shinfield Park, Reading, United Kingdom | Foster Wheeler
Server Support Analyst (Citrix skills required) - Reading Foster Wheeler is a leading international project management, engineering and construction organisation with global construction capabilities working on major projects within upstream oil & gas, midstream & ... more >
Berkshire, Reading, United Kingdom | Foster Wheeler
Microsoft Application Support Specialist - Reading Foster Wheeler is a leading international project management, engineering and construction organisation with global construction capabilities working on major projects within upstream oil & gas, midstream & LNG, refining, ... more >
Solihull, United Kingdom | Enzen Global Limited
Business Analyst - £30,000 - £35000 - Solihull We are in need of a Business Analyst with strong analytical skills and a penchant for learning the domain knowledge of the Utilities sector (Gas industry in ... more >
United Kingdom | University of east anglia
WEB DEVELOPER £22,332 to £27,466 per annum (Grade 6), with agreed progression to £28,290 to £33,780 (Grade 7). Pay award pending from October 2008. We are looking for an experienced Web Developer to join a ... more >
More job opportunities