473,414 Members | 1,723 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Delete Query question

The following select query gives me the set of records I want to delete:
Expand|Select|Wrap|Line Numbers
  1. SELECT tblCaseNumbers.*
  2. FROM (tblCaseNumberDump INNER JOIN [dbo_Final Action] ON tblCaseNumberDump.SSN = [dbo_Final Action].[Primary SS#]) INNER JOIN tblCaseNumbers ON [dbo_Final Action].[Master ID] = tblCaseNumbers.ProspectKey
  3. WHERE (([IDENT]=IIf(Right([ACCT],1)='D','D',IIf(Right([ACCT],1)='A','PLP', IIf(Right([ACCT],1)='B','SLP','M')))));
  4.  
When I try to make it a delete query however:
Expand|Select|Wrap|Line Numbers
  1. DELETE tblCaseNumbers.*
  2. FROM (tblCaseNumberDump INNER JOIN [dbo_Final Action] ON tblCaseNumberDump.SSN = [dbo_Final Action].[Primary SS#]) INNER JOIN tblCaseNumbers ON [dbo_Final Action].[Master ID] = tblCaseNumbers.ProspectKey
  3. WHERE (((tblCaseNumbers.Ident)=IIf(Right([ACCT],1)='D','D', IIf(Right([ACCT],1)='A','PLP',IIf(Right([ACCT],1)='B','SLP','M')))));
  4.  
The delete won't work. I am assuming that it is because of the join? Unfortunately, I cannot change the table structure here. All relationships must remain intact. Can anyone help me on this? I would prefer not to do it with ADODB recordsets....

I am writing a series of queries here. The idea is to take data from a spreadsheet (tblCaseNumberDump) and put it in a usable format in tblCaseNumber. tblCaseNumberDump does not have the foreign key in it, so I am using the SSN as an identifier (it is unique in that table). In tblCaseNumbers, SSN is not unique. The key is a combination of the ProspectKey and Ident. The point of this delete query would be to delete any values in tblCaseNumbers where new data is coming.

Thanks,
Josh
Sep 18 '07 #1
3 1765
MMcCarthy
14,534 Expert Mod 8TB
What table is [ACCT] in? Try the following BTW, reordering the tables may solve the problem.

Expand|Select|Wrap|Line Numbers
  1. DELETE tblCaseNumbers.*
  2. FROM tblCaseNumbers INNER JOIN (tblCaseNumberDump INNER JOIN [dbo_Final Action]
  3. ON tblCaseNumberDump.SSN = [dbo_Final Action].[Primary SS#])
  4. ON tblCaseNumbers.ProspectKey=[dbo_Final Action].[Master ID])
  5. WHERE tblCaseNumbers.Ident=
  6. IIf(Right([ACCT],1)='D','D', 
  7. IIf(Right([ACCT],1)='A','PLP',
  8. IIf(Right([ACCT],1)='B','SLP','M')));
  9.  
Sep 18 '07 #2
ACCT is in the tblCaseNumberDump table. I tried your query below and got the same error message "could not delete from specified tables"

Thanks.

What table is [ACCT] in? Try the following BTW, reordering the tables may solve the problem.

Expand|Select|Wrap|Line Numbers
  1. DELETE tblCaseNumbers.*
  2. FROM tblCaseNumbers INNER JOIN (tblCaseNumberDump INNER JOIN [dbo_Final Action]
  3. ON tblCaseNumberDump.SSN = [dbo_Final Action].[Primary SS#])
  4. ON tblCaseNumbers.ProspectKey=[dbo_Final Action].[Master ID])
  5. WHERE tblCaseNumbers.Ident=
  6. IIf(Right([ACCT],1)='D','D', 
  7. IIf(Right([ACCT],1)='A','PLP',
  8. IIf(Right([ACCT],1)='B','SLP','M')));
  9.  
Sep 20 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
OK this is getting a little creative. Back up your table first in case it all goes wrong.

Expand|Select|Wrap|Line Numbers
  1. DELETE tblCaseNumbers.*
  2. FROM tblCaseNumbers 
  3. WHERE tblCaseNumbers.Ident=
  4. IIf(Right([ACCT],1)='D','D', 
  5. IIf(Right([ACCT],1)='A','PLP',
  6. IIf(Right([ACCT],1)='B','SLP','M')))
  7. AND tblCaseNumbers.ProspectKey=DLookup("[Master ID]","dbo_Final Action","[Primary SS#]=tblCaseNumberDump.SSN");
  8.  
Sep 21 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: robert | last post by:
been ruminating on the question (mostly in a 390/v7 context) of whether, and if so when, a row update becomes an insert/delete. i assume that there is a threshold on the number of columns of the...
5
by: Mike Wiseley | last post by:
I would like to create a delete query that consists of two tables linked together. One table will be the target for the deletions while the other table's equi-joins will tell the delete query which...
2
by: Dave Burt | last post by:
Hi, Access officionados, I'm new here, so please cut me slack/gently tell me off if I'm out of line or in the wrong place. OK, here's something that seems silly (and is also problematic to...
14
by: Karl O. Pinc | last post by:
Hi, Thought perhaps some other eyes than mine can tell if I'm doing something wrong here or if there's a bug somewhere. I've never passed a ROWTYPE varaible to a function but I don't see where...
4
by: Ignoramus6539 | last post by:
There were some strange requests to my server asking for config.php file (which I do not have in the requested location). I did some investigation. Seems to be a virus written in perl,...
17
by: (PeteCresswell) | last post by:
I've got apps where you *really* wouldn't want to delete certain items by accident, but the users just have to have a "Delete" button. My current strategies: Plan A:...
1
by: Matt | last post by:
I am writing a DELETE statement and I want to filter the records using another SELECT statement. My SELECT statement is a GROUP BY query that grabs all social security numbers from the "Data...
5
by: Bob Bridges | last post by:
Start with two tables, parent records in one and child records in the other, a one-to-many relationship. Create a select statement joining the two. Display the query in datasheet mode. When I...
10
by: pythonnoob | last post by:
Hello everyone. New to python as well as this forum, but i must say ive learned a but already reading through some posts. Seems to be a pretty helpful community here. Before i post a question...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.