MS Access Forum / General 2 / August 2008
#Deleted returned by query against linked SQL tables
|
|
Thread rating:  |
Dale Fye - 15 May 2008 16:10 GMT The following query:
SELECT U.User_ID, U.Org, NZ(GV.Gap_Likelihood, 0) as Gap_Likelihood, NZ(GV.Gap_Impact, 0) as Gap_Impact FROM (SELECT User_ID, NZ([Org_Abbr], [Last_Name]) as Org, 29 as GapID FROM tbl_Users WHERE IsSelected <> 0) as U LEFT JOIN tbl_Gap_Voting as GV ON U.User_ID = GV.UserID AND U.GapID = GV.GapID ORDER BY U.Org
returrns values of '#DELETED' for those records in the subquery (U) that do not have matching values in tbl_Gap_Voting. Any ideas why, or how to deal with these results
 Signature HTH Dale
Don''t forget to rate the post if it was helpful!
email address is invalid Please reply to newsgroup only.
Sylvain Lafontaine - 15 May 2008 20:16 GMT Probably because Access doesn't find a main primary key for the resultset because you have hidden it in a subquery. You don't need a subquery here, so remove it and make a regular LEFT JOIN.
 Signature Sylvain Lafontaine, ing. MVP - Technologies Virtual-PC E-mail: sylvain aei ca (fill the blanks, no spam please)
> The following query: > [quoted text clipped - 11 lines] > not have matching values in tbl_Gap_Voting. Any ideas why, or how to deal > with these results Dale Fye - 15 May 2008 21:14 GMT Sylvain,
I need the sub-query because I want the result set to return ALL of the users where IsSelected = True, and the matching (or not) from tbl_Gap_Voting
I've created another query that only returns the matching records, for now, but would really like this result set to display all of the Selected Users, and the values from Gap_Voting, with NULLs where there is no match).
 Signature Dale
email address is invalid Please reply to newsgroup only.
> Probably because Access doesn't find a main primary key for the resultset > because you have hidden it in a subquery. You don't need a subquery here, [quoted text clipped - 15 lines] > > not have matching values in tbl_Gap_Voting. Any ideas why, or how to deal > > with these results Sylvain Lafontaine - 16 May 2008 04:40 GMT > I need the sub-query because I want the result set to return ALL of the > users where IsSelected = True, and the matching (or not) from > tbl_Gap_Voting Without beeing any rude, you seem to make a confusion between a sub-query and a Left Join. What you are describing here is a Left Join, not a sub-query. Remove the sub-query and keep the Left Join and your problem will be solved.
 Signature Sylvain Lafontaine, ing. MVP - Technologies Virtual-PC E-mail: sylvain aei ca (fill the blanks, no spam please)
> Sylvain, > [quoted text clipped - 30 lines] >> > deal >> > with these results Dale Fye - 16 May 2008 11:11 GMT Without being rude, I strongly disagree.
My users table looks something like:
User_ID IsSelected Org Last_Name Dale -1 1 XXX Ted -1 2 YYY Steve -1 3 ZZZ George 0 4 AAA
My Gap_Votes table looks something like:
UserID GapID Gap_Likelihood Gap_Impact Dale 29 5 5 Dale 30 6 6 Ted 29 NULL NULL Ted 30 7 6
With this data, the dataset I would expect to get back is:
User_ID Org Gap_Likelihood Gap_Impact Dale 1 5 5 Ted 2 NULL NULL Steve 3 NULL NULL
You are mistaken for several reasons.
1. As you can see, my Users table does not contain a GapID, so I cannot possibly remove the sub-query without adding WHERE clause that restricts the return recordset to GapID = 29. But as soon as I add that WHERE clause, it would restrict the recordset to only those records where people in the Users table have a matching record in the Gap_Votes table.
2. Likewise, I cannot do as you suggest because to ensure that I get the above recordset I cannot put a WHERE clause at the end of the query to restrict it to users where IsSelected = True, for exactly the same reason.
If you think you see a way to get the recordset I've indicated, without the sub-query and without the LEFT JOIN, please provide it.
Dale
>> I need the sub-query because I want the result set to return ALL of the >> users where IsSelected = True, and the matching (or not) from [quoted text clipped - 40 lines] >>> > deal >>> > with these results Sylvain Lafontaine - 16 May 2008 18:55 GMT Ah, now you are telling us why you want to use a subquery: it's for filtering out the GapId other than 29 before making the Left Join. The obvious solution would be to put this right on the ON statement:
SELECT U.User_ID, IsNull([Org_Abbr], [Last_Name]) as Org, IsNull(GV.Gap_Likelihood, 0) as Gap_Likelihood, IsNull(GV.Gap_Impact, 0) as Gap_Impact
FROM tbl_Users U LEFT JOIN tbl_Gap_Voting as GV on (U.User_ID = GV.UserID AND GV.GapID = 29)
Where U.IsSelected <> 0 ORDER BY U.Org
This query work perfectly on SQL-Server. However, when I try this on Access with ODBC Linked Tables, Access core-dump (but there is no core-dump if using regular Access tables); so I modified it in order to directly filter the table tbl_Gap_Voting by using - guess what? - a sub-query but now we put on where we really want it:
SELECT U.User_ID, Nz([Org_Abbr], [Last_Name]) AS Org, Nz(GV.Gap_Likelihood, 0) AS Gap_Likelihood, Nz(GV.Gap_Impact, 0) AS Gap_Impact FROM dbo_tbl_Users AS U LEFT JOIN [Select * from dbo_tbl_Gap_Voting where GapId=29]. AS GV ON U.User_ID=GV.UserId Where U.IsSelected <> 0 WITH OWNERACCESS OPTION;
Notice that the primary key for the main table is no longer hidden in a subquery and that there is no more #deleting. Notice also that this is patch that we must use only in the case of ODBC linked tables and that again, we see that using ODBC linked tables to address a Sql-server is only, at it's best, a kludge.
 Signature Sylvain Lafontaine, ing. MVP - Technologies Virtual-PC E-mail: sylvain aei ca (fill the blanks, no spam please)
> Without being rude, I strongly disagree. > [quoted text clipped - 82 lines] >>>> > deal >>>> > with these results Dale Fye - 16 May 2008 21:13 GMT Sylvain,
I'll give it a try, thanks for sticking with me on this. I probably should have included the example in my original post.
Dale
> Ah, now you are telling us why you want to use a subquery: it's for > filtering out the GapId other than 29 before making the Left Join. The [quoted text clipped - 119 lines] >>>>> > to deal >>>>> > with these results 疯子哥 - 19 May 2008 04:58 GMT >> I need the sub-query because I want the result set to return ALL of the >> users where IsSelected = True, and the matching (or not) from [quoted text clipped - 40 lines] >>> > deal >>> > with these results Dirtbike - 07 Aug 2008 21:25 GMT I've seen this with my ODBC tables to Cobol code. I find I cannot use select queries with some of my tables....the only thing I can do is make-table. Once the table is made then further filtering is done.
....also, see if there are new ODBC drivers.
....also restart the ODBC server service and possible reboot the ODBC client.
.....also verify the linked table has a valid primary key and that your ODBC client digested table with the key the ODBC table developer intended.
> The following query: > [quoted text clipped - 10 lines] > not have matching values in tbl_Gap_Voting. Any ideas why, or how to deal > with these results
|
|
|