Solved

Update Query

Posted on 2013-01-20
9
230 Views
Last Modified: 2013-01-21
Experts,

I need to confirm what this update query says.
The where condition is saying: dont update if ([import-CSM2].LCID) IS NOT IN [tblLetterOfCredit].[LetterOfCreditID]  but it will update if ([import-CSM2].LCID) IS IN [tblLetterOfCredit].[LetterOfCreditID]

I hope that makes sense.  


UPDATE [import-CSM2] INNER JOIN tblLetterOfCredit ON [import-CSM2].[Reference Number] = tblLetterOfCredit.LCNo SET [import-CSM2].LCID = [tblLetterOfCredit].[LetterOfCreditID]
WHERE ((([import-CSM2].LCID) Not In (SELECT [tblLetterOfCredit].[LetterOfCreditID] From [tblLetterOfCredit])) AND (([import-CSM2].[Actual Status])<>"GEC"));
0
Comment
Question by:pdvsa
  • 6
  • 2
9 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 38799643
I believe you've got things backwards.

Your query as is WILL update if

[import-CSM2].LCID Is Not found In [tblLetterOfCredit].[LetterOfCreditID]
0
 
LVL 28

Expert Comment

by:becraig
ID: 38799644
It is saying update ONLY if the following two conditions are met:
1. import-CSM2].[Actual Status])<>"GEC"
2. import-CSM2].LCID is not present in SELECT [tblLetterOfCredit].[LetterOfCreditID] From [tblLetterOfCredit]
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38799648
Try this instead:

UPDATE [import-CSM2] INNER JOIN tblLetterOfCredit ON [import-CSM2].[Reference Number] = tblLetterOfCredit.LCNo
AND [import-CSM2].LCID  = SELECT [tblLetterOfCredit].[LetterOfCreditID]
 SET [import-CSM2].LCID = [tblLetterOfCredit].[LetterOfCreditID]

Open in new window

0
 
LVL 61

Expert Comment

by:mbizup
ID: 38799652
Correction to include the <> GEC:

UPDATE [import-CSM2] INNER JOIN tblLetterOfCredit ON [import-CSM2].[Reference Number] = tblLetterOfCredit.LCNo
AND [import-CSM2].LCID  = SELECT [tblLetterOfCredit].[LetterOfCreditID]
SET [import-CSM2].LCID = [tblLetterOfCredit].[LetterOfCreditID]
WHERE [import-CSM2].[Actual Status] <>"GEC"

Open in new window

0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:pdvsa
ID: 38799660
mbizup:  

Do you see a syntax in the response right above?  It says there is one.  It highlights [import-CSM2].[Reference Number]  on the first line.  

thanks...
0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 38799693
Yup -- copy/paste issues.  I got the SELECT in there by mistake.

Try this:

UPDATE [import-CSM2] INNER JOIN tblLetterOfCredit 
ON [import-CSM2].[Reference Number] = tblLetterOfCredit.LCNo
AND [import-CSM2].LCID  = [tblLetterOfCredit].[LetterOfCreditID]
 SET [import-CSM2].LCID = [tblLetterOfCredit].[LetterOfCreditID]
WHERE [import-CSM2].[Actual Status] <>"GEC"

Open in new window

0
 
LVL 61

Expert Comment

by:mbizup
ID: 38799703
Or try this:

UPDATE [import-CSM2] INNER JOIN tblLetterOfCredit ON [import-CSM2].[Reference Number] = tblLetterOfCredit.LCNo SET [import-CSM2].LCID = [tblLetterOfCredit].[LetterOfCreditID]
WHERE [import-CSM2].LCID IN (SELECT [tblLetterOfCredit].[LetterOfCreditID] From [tblLetterOfCredit]) AND [import-CSM2].[Actual Status] <>"GEC";

Open in new window

0
 

Author Comment

by:pdvsa
ID: 38799727
perfect.   These queries are difficult.  Both SQL's returned same number of records.

thank you!
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38799759
If they both worked okay, I would opt for the first... I believe it would be better performance-wise.
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 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

19 Experts available now in Live!

Get 1:1 Help Now