Skip to main content
Participating Frequently
June 19, 2009
Answered

Append query won't "run".

  • June 19, 2009
  • 3 replies
  • 3022 views

I made an append query that compares two tables and if they match and the data is not in a 3rd table it appends that data.

This query runs perfectly within access and locally. But as soon as I upload it onto our server it doesnt seem to run. Is there any way to refer to a query that is saved inside of access so that coldfusion will run it?

I can post the code if that may help.

This topic has been closed for replies.
Correct answer paross1

Maybe my logic is wrong. I was trying to state that IF de1 and de2 are equal append those values to de3 if the PWS_id doe nto exist in that table.


Is this more like it?

INSERT INTO de3
( PWS_ID, CCRYear, DateCCRDelivered, DateCCRReceived, DateCertLetterReceived, TNRCC_CCR, URL )
SELECT de2.PWS_ID, de2.CCRYear, de2.DateCCRDelivered, de2.DateCCRReceived, de2.DateCertLetterReceived, de2.TNRCC_CCR, de2.URL
FROM
(de1 INNER JOIN de2 ON (de1.URL = de2.URL) AND
(de1.TNRCC_CCR = de2.TNRCC_CCR) AND
(de1.DateCertLetterReceived = de2.DateCertLetterReceived) AND
(de1.DateCCRReceived = de2.DateCCRReceived) AND
(de1.DateCCRDelivered = de2.DateCCRDelivered) AND
(de1.PWS_ID = de2.PWS_ID) AND
(de1.CCRYear = de2.CCRYear))
WHERE NOT EXISTS(SELECT 1
FROM de3
WHERE  de2.PWS_ID = de3.PWS_ID)

3 replies

Inspiring
June 20, 2009

Now that you have some suggestions on how to do it, why bother?  You already have the data in tables de1 and 2.  What do you hope to accomplish with a 3rd table?

TfortAuthor
Participating Frequently
June 22, 2009

The de3 table is a billing table. The de1 / de2 are both data entrys for quality checks. The code that was posted a few post back seems to do what i want! Thanks guys for all the help.

TfortAuthor
Participating Frequently
June 19, 2009

INSERT INTO de3

( PWS_ID, CCRYear, DateCCRDelivered, DateCCRReceived, DateCertLetterReceived, TNRCC_CCR, URL )

SELECT de2.PWS_ID, de2.CCRYear, de2.DateCCRDelivered, de2.DateCCRReceived, de2.DateCertLetterReceived, de2.TNRCC_CCR, de2.URL

FROM

(de1 INNER JOIN de2 ON (de1.URL = de2.URL) AND

(de1.TNRCC_CCR = de2.TNRCC_CCR) AND

(de1.DateCertLetterReceived = de2.DateCertLetterReceived) AND

(de1.DateCCRReceived = de2.DateCCRReceived) AND

(de1.DateCCRDelivered = de2.DateCCRDelivered) AND

(de1.PWS_ID = de2.PWS_ID) AND

(de1.CCRYear = de2.CCRYear))

LEFT JOIN de3 ON

(de2.TNRCC_CCR = de3.TNRCC_CCR) AND

(de2.URL = de3.URL) AND

(de2.DateCertLetterReceived = de3.DateCertLetterReceived) AND

(de2.DateCCRReceived = de3.DateCCRReceived) AND

(de2.DateCCRDelivered = de3.DateCCRDelivered) AND

(de2.PWS_ID = de3.PWS_ID) AND

(de2.CCRYear = de3.CCRYear)

WHERE

(((de3.PWS_ID) Is Null) AND

((de3.DateCCRDelivered) Is Null) AND

((de3.DateCCRReceived) Is Null) AND

((de3.DateCertLetterReceived) Is Null) AND

((de3.TNRCC_CCR) Is Null) AND

((de3.URL) Is Null) AND

((de3.CCRYear) Is Null));

I hope that helps.

TfortAuthor
Participating Frequently
June 19, 2009

And I just notcied it doesnt even need all those Nulls.. As long as PWS_ID is null it should run it.

Participating Frequently
June 19, 2009

Not sure I "get" your select statement...

How can de2.DateCCRDelivered = de3.DateCCRDelivered when de3.DateCCRReceived Is Null?
How can de2.DateCCRReceived = de3.DateCCRReceived when de3.DateCCRReceived Is Null?
How can de2.DateCertLetterReceived = de3.DateCertLetterReceived when de3.DateCertLetterReceived Is Null?
How can de2.TNRCC_CCR = de3.TNRCC_CCR when de3.TNRCC_CCR Is Null
How can de2.URL = de3.URL when de3.URL Is Null?
How can de2.CCRYear = de3.CCRYear when de3.CCRYear Is Null?
How can de2.PWS_ID = de3.PWS_ID when de3.PWS_ID Is Null?

Phil

Participating Frequently
June 19, 2009

You are probably not going to get a whole lot of suggestions unless you do post your code, since nobody has any idea what you are trying to do.

Phil