Append - with Condition

I need to Append but not all records.
If there is a match between the Projects table and Import-CSM then DO NOT APPEND.
I have the below, but I am not sure of the language for a NOT LIKE criteria

Basically, Append if the criteria is NOT LIKE.  
The ProjectNo and Activity code are text

obviously the below is wrong (it is in plain English)
 
[Projects].[ProjectNo] NOT LIKE [Import-CSM].[Activity Code]

here is the APPEND SQL:
INSERT INTO Projects ( ProjectNo, [Project Name] )
SELECT [Import-CSM].[Activity Code], [Import-CSM].[Activity Description]
FROM [Import-CSM]
WHERE (([Projects].[ProjectNo]<>[Import-CSM].[Activity Code]));

Please see the pic
 AppendNotLIke
pdvsaProject financeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pdvsaProject financeAuthor Commented:
I have NOT EQUAL to in the picture though.  When I run it, a msgbox appears asking for Projects.ProjectNo (I guess because Access cant find the control but it is spelled correctly).  Little difficult to explain.  Please ask if have questions.
0
pdvsaProject financeAuthor Commented:
I need NOT LIKE language
0
pdvsaProject financeAuthor Commented:
The reason I dont want to Append if on that certain NOT LIKE criteria is because if there is a match then that mean that project is already in the db.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Well, first you need the Projects table on the query grid.  And are Project and  Activity Code the same data type?

mx
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
OR ... sounds like you really need this (example tables and names):

SELECT Table1.*
FROM Table1
WHERE (((Table1.FIELD1) Not In (SELECT Table2.FIELD2 FROM Table2;)));

Table1 would be IMPORT-CSM
Table2 would be Projects
Field 1 would be ProjectNo
and Field2 would be Activity Code

mx
0
pdvsaProject financeAuthor Commented:
Mx:  If I am Appending to the Projects table then I thought I did not need it visible in the query grid...

like so in the picture.  I am appending to it so it is not visible...I select Projects after clicking the Append button.  Maybe I am missinging something.


untitled.JPG
0
mbizupCommented:
Make a backup and try revising your original SQL like this:

INSERT INTO Projects ( ProjectNo, [Project Name] )
SELECT [Import-CSM].[Activity Code], [Import-CSM].[Activity Description]
FROM [Import-CSM] LEFT JOIN Projects ON [Projects].[ProjectNo] = [Import-CSM].[Activity Code]
WHERE [Projects].[ProjectNo] IS NULL

0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Sorry ... I missed the APPEND ...
0
pdvsaProject financeAuthor Commented:
OK I did not know I could drag a table in.  

I would need a Not Like instead of the Is Null on project no.
Can you help with that?
I also think I need the same on the [Import-CSM].[Reference Number])

Thank you so much..

Here is how I have it now...just like your previous post but I added tblLetterOfCredit and the criteria on Import-CSM].[Reference Number]

INSERT INTO Projects ( ProjectNo, [Project Name] )
SELECT [Import-CSM].[Activity Code], [Import-CSM].[Activity Description]
FROM ([Import-CSM] LEFT JOIN Projects ON [Import-CSM].[Activity Code] = Projects.[ProjectNo]) INNER JOIN tblLetterOfCredit ON [Import-CSM].[Reference Number] = tblLetterOfCredit.LCNo
WHERE (((Projects.ProjectNo) Is Null)) OR ((([Import-CSM].[Reference Number])<>[LCNo]));


0
peter57rCommented:
If what you are trying to do is add  new records into Projects then do what Miriam said.

You DON'T want 'not like'.
 EVERY import record is 'not like' at least one record in Projects and so wil get appended.
0
mbizupCommented:
Can you post some sample data with desired results?

Do you (as an example) you want to import a record (say [Activity Code] = 'abc') ONLY if there are no records in Projects where ProjectNo is along the lines of 123abc, abc123,xyzabc123 or anything else containing 'abc'?

If that is what you need, you might be able to do something like this (which might be quite slow):

INSERT INTO Projects ( ProjectNo, [Project Name] )
SELECT [Activity Code], [Activity Description]
FROM [Import-CSM]
WHERE DCount("*","Projects","[ProjectNo] LIKE '*" & [Activity Description] & "*'") = 0

Or is it the other way around (ie: you only want to import records where NO PART of [Activity Description] is contained in any [Project Code]?  As Pete said, I don't think this is doable.  

Anyhow, post a little more detail so that we can either get this working with the original two tables or rule it out as impossible before bringing another table in to the mix.




0
keyuCommented:
Hi,

Try like this.

INSERT INTO Projects ( ProjectNo, [Project Name] ) (select  p.ProjectNo, p.[Project Name]  from projects p innerjoin Import-CSM Im on (p.[ProjectNo]<>Im.[Activity Code]));

Hope this Helps..

Thanks,
0
pdvsaProject financeAuthor Commented:
Keyu:  seems to be a syntax error in there (starting at the (select part of it
INSERT INTO Projects ( ProjectNo, [Project Name] ) (select  p.ProjectNo, p.[Project Name]  from projects p innerjoin Import-CSM Im on (p.[ProjectNo]<>Im.[Activity Code]));

Mbizup:
<Or is it the other way around (ie: you only want to import records where NO PART of [Activity Description] is contained in any [Project Code]?  As Pete said, I don't think this is doable.  

yes, this is what I am looking for.  

IDEA:
Maybe I can have the NOT LIKE code outside of the APPEND qry?
(meaning possibly having 2 separate APPEND qry's...
1) if NOT LIKE the APPEND
2) If LIKE then dont do anything


I dont know...just an idea.  I think that Pete and I talked about this before
http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_27197019.html
but I dont know if a Dcount could be applied here or not.  

0
peter57rCommented:
I'm lost.
Some sample data values might help (me, at least).
0
mbizupCommented:
My understanding is that this is reprsentative (and I believe it is impossible)....


Project (we don't want to import records where [Activity Code] contains these strings)
-------
abc
def



Activity Code
--------
abc123
345def
123xyz345   '<--- this would be the only record imported

0
pdvsaProject financeAuthor Commented:
mbizup:  yes, this is true.  
0
keyuCommented:
Hi,

here correct index of the query:

INSERT INTO Projects ( ProjectNo, [Project Name] ) (select  p.ProjectNo, p.[Project Name]  from projects p where (p.[ProjectNo] not in (select m.[Activity Code] from [Import-CSM] m)))

Thnks,
0
peter57rCommented:
Try this as a Select query (check all the names first)..


Select * from Projects as Q where q.ProjectNo Not in
(Select Distinct P.ProjectNo from Projects as P , Import_csm as I
where  instr(I.[Activity code] , P.Projectno)>0)
0
pdvsaProject financeAuthor Commented:
Keyu:  
seems as though there is a syntax error after running.  
It highlights at the bold part:
INSERT INTO Projects (ProjectNo, [Project Name] ) (select  p.ProjectNo, p.[Project Name]  from projects p where (p.[ProjectNo] not in (select m.[Activity Code] from [Import-CSM] m)))

Peter:  seems like I have a syntax as well....see picture please

thank you for the help...I know it is difficult if cant see project.  

(I do have the db here if you want to take a peek...it is pared down and only contains the necessary)
https://skydrive.live.com/redir.aspx?cid=501a06dcdb8cc24b&resid=501A06DCDB8CC24B!1908


untitled.JPG
0
peter57rCommented:
I don't get an error running my query in your database.
0
pdvsaProject financeAuthor Commented:
Peter:  did you change the name of the table

from
Import_csm

to
Import-csm

after I made the change it gives me the error.
0
peter57rCommented:
yes I changed the table name.

I'm attaching my version.  Just run query1.
db-Import2k7.accdb
0
pdvsaProject financeAuthor Commented:
OK ...no syntax now.  

However, I do have an issue.  
When I run query1 it returns 24 records.
It should return many more.

REason:  if there is no match between import-csm.Activity Code and Projects.ProjectNo then import the ones from Import-csm that dont have a match (meaning NOT LIKE i guess) on Projects.ProjectNo  

this means that I am importing the ones that are not already in the db contained under the Projects table.  Another way of saying is I am adding what is in table import-csm that is not already contained in table projects. if I did then there would be duplicates.

I hope it makes better sense now.  
What is next?  Let me know what you decide.  

----------here is the SQL of query1
SELECT *
FROM Projects AS Q
WHERE (((Q.ProjectNo) Not In (Select Distinct P.ProjectNo from Projects as P , [Import-csm] as I
where  instr(I.[Activity code] , P.Projectno)>0)));


I attached an excel spreadsheet...
Matches-Peter.xls
0
peter57rCommented:
OK.
I had it the wrong way round.

Have a look at this version.
Query1 should show the data to be imported, based on what I now understand.

db-Import2k7a.accdb
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pdvsaProject financeAuthor Commented:
that was it.  thank you
0
keyuCommented:
you have not followed exact syntex writen by me..its working fine with me.

anyways thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.