G
Guest
Hello,
I am not very familair with subqueries and thus I am having trobubles. I
have a query that pulls back say 1000 records. Then I have a subquery in the
first query that I am using to determine if the a recorded pulled meets some
criteria for additional processing. The subquery seems to be causing a loop.
Like it is processing each 1000 records of the first query for each record
of the first.
I used a subquery because I could not get a SQL IF statement to run
correctly in Access. I am trying to determine if the records pulled from the
first query is the first record of its type in the database. The query that
I am running through Access is querying a SQL database through an ODBC call.
Below is part of the main query and the entire subquery.
***Main query***
SELECT TOP 1000 Trim(dbo_dealer.ext_name) AS Dealer, Trim(dbo_deals.deal_no)
AS Quantum
***Sub Query ***
(Select top 1 Afn.deal_no
From dbo_deals Afn
where Afn.mature_dt=dbo_deals.cur_mat_dt and Afn.trans_type = "fx" and
Afn.ccy=dbo_deals.ccy and Afn.ccy2=dbo_deals.ccy2 order by Afn.deal_dt,
Afn.deal_no) AS firstNext,
***Additional processing back in the main query after the sub runs***
IIf(firstNext=dbo_deals.deal_no,"first","next") AS firstNextText
I am not very familair with subqueries and thus I am having trobubles. I
have a query that pulls back say 1000 records. Then I have a subquery in the
first query that I am using to determine if the a recorded pulled meets some
criteria for additional processing. The subquery seems to be causing a loop.
Like it is processing each 1000 records of the first query for each record
of the first.
I used a subquery because I could not get a SQL IF statement to run
correctly in Access. I am trying to determine if the records pulled from the
first query is the first record of its type in the database. The query that
I am running through Access is querying a SQL database through an ODBC call.
Below is part of the main query and the entire subquery.
***Main query***
SELECT TOP 1000 Trim(dbo_dealer.ext_name) AS Dealer, Trim(dbo_deals.deal_no)
AS Quantum
***Sub Query ***
(Select top 1 Afn.deal_no
From dbo_deals Afn
where Afn.mature_dt=dbo_deals.cur_mat_dt and Afn.trans_type = "fx" and
Afn.ccy=dbo_deals.ccy and Afn.ccy2=dbo_deals.ccy2 order by Afn.deal_dt,
Afn.deal_no) AS firstNext,
***Additional processing back in the main query after the sub runs***
IIf(firstNext=dbo_deals.deal_no,"first","next") AS firstNextText