PC Review


Reply
Thread Tools Rate Thread

Access VBA SQL problem

 
 
Magius96
Guest
Posts: n/a
 
      2nd Oct 2008
I need to delete records from my table when a field in another table does not
contain a certain value. I have the following SQL that selects the correct
accounts, but when I try to run it, it says it can't delete records from the
table. I can't figure out why!

DELETE PLD.* FROM AIS RIGHT JOIN PLD ON AIS.DEBTOR_FILENO =
PLD.DEBTOR_FILENO WHERE (((IIf([AIS].[ED_CUR_COND]<>'REHAB' Or
[AIS].[ED_FALLOUT_DT] Is Not Null Or
[AIS].[ED_FALLOUT_DT]>[PLD].[ED_COND_OPEN_DT] Or [AIS].[ED_FALLOUT_RSN] Is
Not Null,1,0))=1))

Can anyone give me some directive to get this working?
In english, Records should be deleted from the PLD table if in the AIS
table the condition is not 'REHAB', or there is a Fallout date that is after
the setup date, or there is a fallout reason.

The three fields being referenced in the AIS table do not exist in the PLD
table. The two tables are linked using file numbers. We can't create
relations in the database, and have to setup the relations on a query by
query basis because some queries require the relations to be set differently.
 
Reply With Quote
 
 
 
 
Alex Dybenko
Guest
Posts: n/a
 
      2nd Oct 2008
Hi,
first try use distinctrow as here:
http://accessblog.net/2004/10/access...ql-in-jet.html

second - try to use left join:

FROM PLD LEFT JOIN AIS

--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com

"Magius96" <(E-Mail Removed)> wrote in message
news:955A8761-57D9-4311-A1D3-(E-Mail Removed)...
> I need to delete records from my table when a field in another table does
> not
> contain a certain value. I have the following SQL that selects the
> correct
> accounts, but when I try to run it, it says it can't delete records from
> the
> table. I can't figure out why!
>
> DELETE PLD.* FROM AIS RIGHT JOIN PLD ON AIS.DEBTOR_FILENO =
> PLD.DEBTOR_FILENO WHERE (((IIf([AIS].[ED_CUR_COND]<>'REHAB' Or
> [AIS].[ED_FALLOUT_DT] Is Not Null Or
> [AIS].[ED_FALLOUT_DT]>[PLD].[ED_COND_OPEN_DT] Or [AIS].[ED_FALLOUT_RSN] Is
> Not Null,1,0))=1))
>
> Can anyone give me some directive to get this working?
> In english, Records should be deleted from the PLD table if in the AIS
> table the condition is not 'REHAB', or there is a Fallout date that is
> after
> the setup date, or there is a fallout reason.
>
> The three fields being referenced in the AIS table do not exist in the PLD
> table. The two tables are linked using file numbers. We can't create
> relations in the database, and have to setup the relations on a query by
> query basis because some queries require the relations to be set
> differently.


 
Reply With Quote
 
John Spencer
Guest
Posts: n/a
 
      2nd Oct 2008
STEP 1: BACKUP your data before attempting the following.
STEP 2: BACKUP your data before attempting the following.

Without a backup you cannot restore the data if this does not work the way you
expect.

DELETE PLD.*
FROM PLD
WHERE DEBTORFileNO IN
(SELECT AIS.DebtorFileNo
FROM AIS RIGHT JOIN PLD
ON AIS.DEBTOR_FILENO = PLD.DEBTOR_FILENO
WHERE IIf([AIS].[ED_CUR_COND]<>'REHAB' Or
[AIS].[ED_FALLOUT_DT] Is Not Null Or
[AIS].[ED_FALLOUT_DT]>[PLD].[ED_COND_OPEN_DT] Or
[AIS].[ED_FALLOUT_RSN] Is Not Null,1,0)=1)

I can't understand why you have used an IIF expression in the where clause. I
would think it would have been more straightforward without the complexity of
the IIF.
SELECT AIS.DebtorFileNo
FROM AIS RIGHT JOIN PLD
ON AIS.DEBTOR_FILENO = PLD.DEBTOR_FILENO
WHERE IIf([AIS].[ED_CUR_COND]<>'REHAB' Or
[AIS].[ED_FALLOUT_DT] Is Not Null Or
[AIS].[ED_FALLOUT_DT]>[PLD].[ED_COND_OPEN_DT] Or
[AIS].[ED_FALLOUT_RSN] Is Not Null


John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

Magius96 wrote:
> I need to delete records from my table when a field in another table does not
> contain a certain value. I have the following SQL that selects the correct
> accounts, but when I try to run it, it says it can't delete records from the
> table. I can't figure out why!
>
> DELETE PLD.* FROM AIS RIGHT JOIN PLD ON AIS.DEBTOR_FILENO =
> PLD.DEBTOR_FILENO WHERE (((IIf([AIS].[ED_CUR_COND]<>'REHAB' Or
> [AIS].[ED_FALLOUT_DT] Is Not Null Or
> [AIS].[ED_FALLOUT_DT]>[PLD].[ED_COND_OPEN_DT] Or [AIS].[ED_FALLOUT_RSN] Is
> Not Null,1,0))=1))
>
> Can anyone give me some directive to get this working?
> In english, Records should be deleted from the PLD table if in the AIS
> table the condition is not 'REHAB', or there is a Fallout date that is after
> the setup date, or there is a fallout reason.
>
> The three fields being referenced in the AIS table do not exist in the PLD
> table. The two tables are linked using file numbers. We can't create
> relations in the database, and have to setup the relations on a query by
> query basis because some queries require the relations to be set differently.

 
Reply With Quote
 
Steve Sanford
Guest
Posts: n/a
 
      2nd Oct 2008
"John Spencer" wrote:

> STEP 1: BACKUP your data before attempting the following.
> STEP 2: BACKUP your data before attempting the following.
>


And don't forget:

STEP 3: BACKUP your data


From (the book you wish you had read): "The 3 Rules of Computing"



--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with Access 2003 User Security DB opening with Access 2007 Donna Microsoft Access Security 4 20th May 2010 05:58 PM
Access 97 Upgraded to Access 2007 User level security problem Derek Curtis Microsoft Access Security 3 6th Sep 2008 05:50 AM
[Access 2007] Problem to disable the Close Button (X) on the Access Application Window David Berthemet Microsoft Access 0 28th Feb 2007 11:33 AM
Access 2003: Problem with Access.Application object when user not logged in Henk Microsoft Access Reports 1 9th Mar 2006 01:57 AM
Problem running Access 2003 and Access 2000 apps on same machine. Rathtap Microsoft Access 3 13th Jun 2004 01:30 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:42 PM.