Solved

Update Query Using Left()

Posted on 2015-01-20
2
140 Views
Last Modified: 2015-01-20
Hello,

I want to split a field in two but I got the first part working but can't seem to get the second half of the sql working

UPDATE MyTableName SET MyTableName.FirstPart = Left([Combo] & " ",InStr([Combo] & " "," ")-1);


The second part should contain the Right()  but since the amount of data fluctuates I can't seem to get it right.


I tried using 2, and 28 respectively but that isn't consistant. What is is the first part I got here except too that if there are no "Characters" such as AB then leave it alone for the Left() (should be an IIF statement?) but lost on how to configure that one, then the rest should be on the Right()

any Ideas?
0
Comment
Question by:Ernest Grogg
2 Comments
 
LVL 35

Accepted Solution

by:
PatHartman earned 500 total points
ID: 40560488
Because the left is variable, the right is also so you have to use Mid() instead

UPDATE MyTableName SET MyTableName.FirstPart = Left([Combo] & " ",InStr([Combo] & " "," ")-1)
MyTableName.SecondPart = Mid(Combo, Instr(Combo, ",") + 1);

If there is "always" a space after the comma, then use +2 to get the starting point for the second half of the string.

If the reason you are concatenating the space after the combo is to handle, nulls, you can use the NZ() function instead.
MyTableName.SecondPart = Mid(Combo, Nz(Instr(Combo, ","), 0) + 1);
0
 

Author Comment

by:Ernest Grogg
ID: 40560566
Perfect.  Here is what worked for me:



UPDATE MyTableName SET MyTableName.FirstPart = Left([Combo] & " ",InStr([Combo] & "2","2")-1), MyTableName.SecondPart= Mid([Combo],NZ(InStr([Combo],""),0)+2);


Thanks!
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

810 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