Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Update Query Using Left()

Posted on 2015-01-20
2
Medium Priority
?
157 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 39

Accepted Solution

by:
PatHartman earned 2000 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 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