Solved

Update Query Using Left()

Posted on 2015-01-20
2
132 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 34

Accepted Solution

by:
PatHartman earned 500 total points
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
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 stored procedures 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 Micr…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

772 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

12 Experts available now in Live!

Get 1:1 Help Now