Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bug: Derived/Nested table syntax error (caused by Access!!!!!)

Status
Not open for further replies.

TheInsider

Programmer
Jul 17, 2000
796
0
0
CA
Hi,<br>&nbsp;I have stumbled accross a bug in Access 2000. Access 2000 allows you to use derived or nested tables, however I have found an interesting phenomenon: If you enter the query below into the SQL view, Access 2000 will accept this as it is and will allow you to save the query, view it in design view, and will even run the query perfectly. However, upon closing the query and then re-entering it, Access changes some of the syntax. For example it changes &quot;LEFT JOIN(SELECT ) AS&quot; to &quot;LEFT JOIN [SELECT ]. AS&quot; . The problem is that this syntax causes a sytax error!!! If you take the &quot;[].&quot; out and replace them with &quot;()&quot; again, you can save the query, view it in design view, and run it. Once again, if you close the query, the syntax is changed back to the incorrect syntax. If you open/run the query with the invalid syntax, it will run fine, but if you choose to open it in design view, it will go to SQL view and won't let you save it, view it in design view, or run it. Crystal Reports won't touch this query with a ten foot pole while it is in this state. Both the unchanged and changed queries are listed below, but you can see this phenomenon with a much simpler query. If someone knows what the heck Access is doing, please let me know!<br><br>------------------------------------------------------------<br>Unchanged Query:<br>------------------------------------------------------------<br>PARAMETERS LastName Text ( 255 ), ContractNumber Text ( 255 ), FundName Text ( 255 ), ContractStartDate DateTime, ContractEndDate DateTime, TransactionStartDate DateTime, TransactionEndDate DateTime;<br>SELECT [fldLastName] & &quot;, &quot; & [fldFirstName] & &quot; &quot; & [fldMiddleInitial] AS fldContractOwner, tbdClientContracts.fldContractNumber, qryContractStartDate.fldContractStartDate, tbdFunds.fldFundName, tbdClientFunds.fldInitialCommission, qryInitialCommission.fldCommissionEarned, tbdClientFunds.fldTrailerCommission, qryTrailerCommission.fldCommissionEarned<br>FROM tbdClients RIGHT JOIN (((tbdClientContracts LEFT JOIN (SELECT tbdClientContracts.fldContractNumber, Min(tbdDeposits.fldDateOfDeposit) AS fldContractStartDate<br>FROM tbdClientContracts LEFT JOIN tbdDeposits ON tbdClientContracts.fldContractNumber = tbdDeposits.fldContractNumber<br>GROUP BY tbdClientContracts.fldContractNumber) AS qryContractStartDate ON tbdClientContracts.fldContractNumber = qryContractStartDate.fldContractNumber) LEFT JOIN ((tbdClientFunds LEFT JOIN (SELECT tbdClientFunds.fldContractNumber, tbdClientFunds.fldFundID, ([SumOffldDepositValue]-IIf(IsNull([SumOffldWithdrawValue]),0,[SumOffldWithdrawValue]))*[fldInitialCommission] AS fldCommissionEarned<br>FROM (tbdClientFunds LEFT JOIN (SELECT tbdDeposits.fldContractNumber, tbdDeposits.fldFundID, Sum(tbdDeposits.fldDepositValue) AS SumOffldDepositValue<br>FROM tbdDeposits<br>WHERE (((DateDiff(&quot;d&quot;,[fldDateOfDeposit],Date()))&lt;365) AND ((tbdDeposits.fldDateOfDeposit)&gt;=[TransactionStartDate] And (tbdDeposits.fldDateOfDeposit)&lt;=[TransactionEndDate]))<br>GROUP BY tbdDeposits.fldContractNumber, tbdDeposits.fldFundID) AS qryInitialDeposits ON (tbdClientFunds.fldFundID = qryInitialDeposits.fldFundID) AND (tbdClientFunds.fldContractNumber = qryInitialDeposits.fldContractNumber)) LEFT JOIN (SELECT tbdWithdraws.fldContractNumber, tbdWithdraws.fldFundID, Sum(tbdWithdraws.fldWithdrawValue) AS SumOffldWithdrawValue<br>FROM tbdWithdraws<br>WHERE (((DateDiff(&quot;d&quot;,[fldDateOfWithdraw],Date()))&lt;365) AND ((tbdWithdraws.fldDateOfWithdraw)&gt;=[TransactionStartDate] And (tbdWithdraws.fldDateOfWithdraw)&lt;=[TransactionEndDate]))<br>GROUP BY tbdWithdraws.fldContractNumber, tbdWithdraws.fldFundID) AS qryInitialWithdraws ON (tbdClientFunds.fldFundID = qryInitialWithdraws.fldFundID) AND (tbdClientFunds.fldContractNumber = qryInitialWithdraws.fldContractNumber)) AS qryInitialCommission ON (tbdClientFunds.fldContractNumber = qryInitialCommission.fldContractNumber) AND (tbdClientFunds.fldFundID = qryInitialCommission.fldFundID)) LEFT JOIN (SELECT tbdClientFunds.fldContractNumber, tbdClientFunds.fldFundID, ([SumOffldDepositValue]-IIf(IsNull([SumOffldWithdrawValue]),0,[SumOffldWithdrawValue]))*[fldTrailerCommission] AS fldCommissionEarned<br>FROM (tbdClientFunds LEFT JOIN (SELECT tbdDeposits.fldContractNumber, tbdDeposits.fldFundID, Sum(tbdDeposits.fldDepositValue) AS SumOffldDepositValue<br>FROM tbdDeposits<br>WHERE (((DateDiff(&quot;d&quot;,[fldDateOfDeposit],Date()))&gt;=365) AND ((tbdDeposits.fldDateOfDeposit)&gt;=[TransactionStartDate] And (tbdDeposits.fldDateOfDeposit)&lt;=[TransactionEndDate]))<br>GROUP BY tbdDeposits.fldContractNumber, tbdDeposits.fldFundID) AS qryTrailerDeposits ON tbdClientFunds.fldContractNumber = qryTrailerDeposits.fldContractNumber) LEFT JOIN (SELECT tbdWithdraws.fldContractNumber, tbdWithdraws.fldFundID, Sum(tbdWithdraws.fldWithdrawValue) AS SumOffldWithdrawValue<br>FROM tbdWithdraws<br>WHERE (((DateDiff(&quot;d&quot;,[fldDateOfWithdraw],Date()))&gt;=365) AND ((tbdWithdraws.fldDateOfWithdraw)&gt;=[TransactionStartDate] And (tbdWithdraws.fldDateOfWithdraw)&lt;=[TransactionEndDate]))<br>GROUP BY tbdWithdraws.fldContractNumber, tbdWithdraws.fldFundID) AS qryTrailerWithdraws ON qryTrailerDeposits.fldContractNumber = qryTrailerWithdraws.fldContractNumber) AS qryTrailerCommission ON (tbdClientFunds.fldContractNumber = qryTrailerCommission.fldContractNumber) AND (tbdClientFunds.fldFundID = qryTrailerCommission.fldFundID)) ON tbdClientContracts.fldContractNumber = tbdClientFunds.fldContractNumber) LEFT JOIN tbdFunds ON tbdClientFunds.fldFundID = tbdFunds.fldFundID) ON tbdClients.fldClientID = tbdClientContracts.fldClientID<br>WHERE (((tbdClientContracts.fldContractNumber) Like [ContractNumber]) AND ((qryContractStartDate.fldContractStartDate)&gt;=[ContractStartDate] And (qryContractStartDate.fldContractStartDate)&lt;=[ContractEndDate]) AND ((tbdFunds.fldFundName) Like [FundName]) AND ((qryInitialCommission.fldCommissionEarned) Is Not Null) AND ((tbdClients.fldLastName) Like [LastName])) OR (((qryTrailerCommission.fldCommissionEarned) Is Not Null));<br>------------------------------------------------------------<br>Changed Query:<br>------------------------------------------------------------<br>PARAMETERS LastName Text ( 255 ), ContractNumber Text ( 255 ), FundName Text ( 255 ), ContractStartDate DateTime, ContractEndDate DateTime, TransactionStartDate DateTime, TransactionEndDate DateTime;<br>SELECT [fldLastName] & &quot;, &quot; & [fldFirstName] & &quot; &quot; & [fldMiddleInitial] AS fldContractOwner, tbdClientContracts.fldContractNumber, qryContractStartDate.fldContractStartDate, tbdFunds.fldFundName, tbdClientFunds.fldInitialCommission, qryInitialCommission.fldCommissionEarned, tbdClientFunds.fldTrailerCommission, qryTrailerCommission.fldCommissionEarned<br>FROM tbdClients RIGHT JOIN (((tbdClientContracts LEFT JOIN [SELECT tbdClientContracts.fldContractNumber, Min(tbdDeposits.fldDateOfDeposit) AS fldContractStartDate<br>FROM tbdClientContracts LEFT JOIN tbdDeposits ON tbdClientContracts.fldContractNumber = tbdDeposits.fldContractNumber<br>GROUP BY tbdClientContracts.fldContractNumber]. AS qryContractStartDate ON tbdClientContracts.fldContractNumber = qryContractStartDate.fldContractNumber) LEFT JOIN ((tbdClientFunds LEFT JOIN [SELECT tbdClientFunds.fldContractNumber, tbdClientFunds.fldFundID, ([SumOffldDepositValue]-IIf(IsNull([SumOffldWithdrawValue]),0,[SumOffldWithdrawValue]))*[fldInitialCommission] AS fldCommissionEarned<br>FROM (tbdClientFunds LEFT JOIN (SELECT tbdDeposits.fldContractNumber, tbdDeposits.fldFundID, Sum(tbdDeposits.fldDepositValue) AS SumOffldDepositValue<br>FROM tbdDeposits<br>WHERE (((DateDiff(&quot;d&quot;,[fldDateOfDeposit],Date()))&lt;365) AND ((tbdDeposits.fldDateOfDeposit)&gt;=[TransactionStartDate] And (tbdDeposits.fldDateOfDeposit)&lt;=[TransactionEndDate]))<br>GROUP BY tbdDeposits.fldContractNumber, tbdDeposits.fldFundID) AS qryInitialDeposits ON (tbdClientFunds.fldFundID = qryInitialDeposits.fldFundID) AND (tbdClientFunds.fldContractNumber = qryInitialDeposits.fldContractNumber)) LEFT JOIN (SELECT tbdWithdraws.fldContractNumber, tbdWithdraws.fldFundID, Sum(tbdWithdraws.fldWithdrawValue) AS SumOffldWithdrawValue<br>FROM tbdWithdraws<br>WHERE (((DateDiff(&quot;d&quot;,[fldDateOfWithdraw],Date()))&lt;365) AND ((tbdWithdraws.fldDateOfWithdraw)&gt;=[TransactionStartDate] And (tbdWithdraws.fldDateOfWithdraw)&lt;=[TransactionEndDate]))<br>GROUP BY tbdWithdraws.fldContractNumber, tbdWithdraws.fldFundID) AS qryInitialWithdraws ON (tbdClientFunds.fldFundID = qryInitialWithdraws.fldFundID) AND (tbdClientFunds.fldContractNumber = qryInitialWithdraws.fldContractNumber)]. AS qryInitialCommission ON (tbdClientFunds.fldFundID = qryInitialCommission.fldFundID) AND (tbdClientFunds.fldContractNumber = qryInitialCommission.fldContractNumber)) LEFT JOIN [SELECT tbdClientFunds.fldContractNumber, tbdClientFunds.fldFundID, ([SumOffldDepositValue]-IIf(IsNull([SumOffldWithdrawValue]),0,[SumOffldWithdrawValue]))*[fldTrailerCommission] AS fldCommissionEarned<br>FROM (tbdClientFunds LEFT JOIN (SELECT tbdDeposits.fldContractNumber, tbdDeposits.fldFundID, Sum(tbdDeposits.fldDepositValue) AS SumOffldDepositValue<br>FROM tbdDeposits<br>WHERE (((DateDiff(&quot;d&quot;,[fldDateOfDeposit],Date()))&gt;=365) AND ((tbdDeposits.fldDateOfDeposit)&gt;=[TransactionStartDate] And (tbdDeposits.fldDateOfDeposit)&lt;=[TransactionEndDate]))<br>GROUP BY tbdDeposits.fldContractNumber, tbdDeposits.fldFundID) AS qryTrailerDeposits ON tbdClientFunds.fldContractNumber = qryTrailerDeposits.fldContractNumber) LEFT JOIN (SELECT tbdWithdraws.fldContractNumber, tbdWithdraws.fldFundID, Sum(tbdWithdraws.fldWithdrawValue) AS SumOffldWithdrawValue<br>FROM tbdWithdraws<br>WHERE (((DateDiff(&quot;d&quot;,[fldDateOfWithdraw],Date()))&gt;=365) AND ((tbdWithdraws.fldDateOfWithdraw)&gt;=[TransactionStartDate] And (tbdWithdraws.fldDateOfWithdraw)&lt;=[TransactionEndDate]))<br>GROUP BY tbdWithdraws.fldContractNumber, tbdWithdraws.fldFundID) AS qryTrailerWithdraws ON qryTrailerDeposits.fldContractNumber = qryTrailerWithdraws.fldContractNumber]. AS qryTrailerCommission ON (tbdClientFunds.fldFundID = qryTrailerCommission.fldFundID) AND (tbdClientFunds.fldContractNumber = qryTrailerCommission.fldContractNumber)) ON tbdClientContracts.fldContractNumber = tbdClientFunds.fldContractNumber) LEFT JOIN tbdFunds ON tbdClientFunds.fldFundID = tbdFunds.fldFundID) ON tbdClients.fldClientID = tbdClientContracts.fldClientID<br>WHERE (((tbdClientContracts.fldContractNumber) Like [ContractNumber]) AND ((qryContractStartDate.fldContractStartDate)&gt;=[ContractStartDate] And (qryContractStartDate.fldContractStartDate)&lt;=[ContractEndDate]) AND ((tbdFunds.fldFundName) Like [FundName]) AND ((qryInitialCommission.fldCommissionEarned) Is Not Null) AND ((tbdClients.fldLastName) Like [LastName])) OR (((qryTrailerCommission.fldCommissionEarned) Is Not Null));<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top