given 2 tables containing:
sid's; 10,20,30,40,50,60,70,80
cid's; 11,12,13,14,15,16,17
and one Table S referencing to cid's to sid
attempting to generate Table C referencing sid's to cid
currently working with the following test query which gets close ... the reason I started this thread was that the actual query where table S is actually output from another Query where the Select top 1 returns an error (query won't run) stating W.cidw may return more then one instance of s.cids ... this test query at least runs ... the only thing I can think of is the actual query results are affecting the 2nd Query ... also having other issues where I make a change to a query and the only way it will run is if I copy the SQL code to a brand new Query.
Been working on this query for several days now so hoping someone can point me in the right direction
sid's; 10,20,30,40,50,60,70,80
cid's; 11,12,13,14,15,16,17
and one Table S referencing to cid's to sid
Code:
sid cidw cids cidt
10 11 11 -
20 - 13 -
30 13 - -
40 11 11 -
50 14 - -
60 - 12 15
70 16 17 -
80 - 14 -
Code:
cid sids sidw cidt
11 10 10 -
11 40 40 -
12 60 - 15
13 20 30 -
14 80 50 -
16 - 70 -
17 70 - -
Code:
Test Query
SELECT
IIF(cids <> "",cids, cidw) AS cid,
s.sid AS sids,
IIf((cids<>"" And cids=cidw) Or (cidw<>"" And Len(cids)=0),
sid,
(select top 1 sid from s as w where w.cidw = s.cids)
) AS sidw,
s.cidt
FROM s
ORDER BY IIF(cids<>"",cids,cidw);