Solved

Update Query - leading Zeros or dashes

Posted on 2013-01-20
17
474 Views
Last Modified: 2013-01-20
Experts,

I have been updating with an update query with no issues until today.
I noticed the query will not update if there are either dashes or leading zeros in the data I am importing.

I import data from excel then update my db data according to the where condition.
The update query updates if ([Import-DnB].[L/C Ref])=[LCNo]

The problem record was as follows: (notice leading zeros and dashes)
[Import-DnB].[L/C Ref] = 00440-02-000-2585

The record would not update with that type of number
I thought there could be some issue with the leading zeros or dashes.
I changed [Import-DnB].[L/C Ref] to 1111 (removing the dashes and leading zeros) and my problem was solved but I have to be able to update with leading zeros or dashes.

I imagine some experts have encountered this before and know how to modify the below sql to allow the update even with dashes or leading zeros.
 
The fields are formatted as TEXT and not number as L/C Ref has letters sometimes.  

Here is the SQL of the update query:
UPDATE [Import-DnB], tblLetterOfCredit SET [Import-DnB].LCID_dnb = [tblLetterOfCredit].[LetterOfCreditID]
WHERE ((([Import-DnB].[L/C Ref])=[LCNo]));

thank you for the help...

UpdateQry
0
Comment
Question by:pdvsa
[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
  • 8
  • 5
  • 4
17 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 38799007
Try changing your criteria

Where cstr([l/c no]) = cstr(lcno)
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38799010
L/c no should be l/c ref in my previous comment
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 38799013
are the LCNo does not have leading zeros?

try this

WHERE Replace([Import-DnB].[L/C Ref],"-","")="00" & [LCNo];
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:pdvsa
ID: 38799055
mbizup:
I get an error with placing the cstr:
UPDATE [Import-DnB], tblLetterOfCredit SET [Import-DnB].LCID_dnb = [tblLetterOfCredit].[LetterOfCreditID]
WHERE ((cstr([Import-DnB].[L/C Ref])=cstr[LCNo]));

Capricorn:
I changed the where condition but after I did it did not return any results.  

thanks....
0
 

Author Comment

by:pdvsa
ID: 38799058
The LCNo's do have to remain intact meaning I can not modify the LCNo.
0
 

Author Comment

by:pdvsa
ID: 38799060
or LCRef...I have to import the data as is.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 38799073
why don't you try the where clause i posted?
0
 

Author Comment

by:pdvsa
ID: 38799090
Capricorn, i did try it.  Maybe you missed my response.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 38799100
so, what is the result?
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38799210
Using a cellphone so I can't easily copy paste your code, but your parentheses are mismatched the way you applied the second cstr.  It should end with

= cstr([lcno]));
0
 

Author Comment

by:pdvsa
ID: 38799220
Capricorn, i think your method is altering the LCNo if not mistaken.  I have to keep the integrity if the text.  I changed the where condition to what you said but when ran there were no results (pressed the datasheet to see if any results).  If i ran, i dont think it would have updated.

I am on cell.  Can not test.  Will do so soon.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 38799254
<, i think your method is altering the LCNo if not mistaken>
<I have to keep the integrity if the text.>

the  LCNo  will not change

answer this question

are the LCNo does not have leading zeros?

or post sample values of [ LCNo ]
0
 

Author Comment

by:pdvsa
ID: 38799272
Oh ok i hought it was Replacing... Sorry.  They do have leading 0's.  The format is text if that makes a difference.  Will be at computer in a couPle hours.
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 38799329
< They do have leading 0'>

ok, then try this

WHERE Replace([Import-DnB].[L/C Ref],"-","")= [LCNo];
0
 

Author Comment

by:pdvsa
ID: 38799533
Capricorn:  that worked.  ...thank you.

Mbizup:  
I tried to add the paren but still had a syntax.  I added another paren at the very end (as it highlighted the very end) but said "invalid use of Null" when ran:
UPDATE [Import-DnB], tblLetterOfCredit SET [Import-DnB].LCID_dnb = [tblLetterOfCredit].[LetterOfCreditID]
WHERE ((cstr([Import-DnB].[L/C Ref])=cstr([LCNo])));
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38799554
Your syntax still looks off.

Just a couple of general tips with these sql statements...

Access throws in a lot of unneeded parentheses that tend to confuse/complicate things.  These SQL statements are generally easier to understand and to write correctly if you keep the parentheses to a minimum (either by custom coding or by removing the extra parentheses that Access adds).  That's why I wrote my original post the way I did (you don't need all of the parentheses and brackets that you have in your SQL statements):

Where cstr([l/c ref]) = cstr(lcno)

That said - my original suggestion was a guess based on a misunderstanding of the question.  I didn't realize that you were actually trying to match text in one field with different text in another field - so this suggestion, even if the syntax is corrected is not going to work.
0
 

Author Comment

by:pdvsa
ID: 38799594
ahh I see.  Thanks for the tip.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
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 …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

617 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