At Most One Record Can Be Returned By Subquery After Appending New Rows
Jun 18, 2012
I have a subquery on a table which got the previous and next rows from a table. This worked fine, until I started replacing my table with real data instead of dummy-data. I now receive the "at most one record can be returned by subquery" error every time I run it. I checked that I do not have any identical rows.
My query:
Code:
SELECT z.DateFrom, z.DateTo, z.ArticleID, z.retailerID, z.Actuals, z.Statistical, (SELECT y.Actuals FROM tblActuals AS y WHERE (y.retailerID=z.retailerID) AND (y.ArticleID=z.ArticleID) AND ((DatePart("ww",z.DateFrom,2,3)-1)=DatePart("ww",y.DateFrom,2,3))) AS ActualsMin1 FROM tblActuals AS z;
I append new rows via a VBA-script from another table.
View Replies
ADVERTISEMENT
Mar 21, 2007
I have a strange 'bug'.
I wrote a query to return the TOP 32 items for a key. Works fine:-
SELECT TOP 32 [my Disks Coefficients sub].[thier Disk ID] FROM [my Disks Coefficients] AS [my Disks Coefficients sub] WHERE [my Disks Coefficients sub].[my Disk ID]=1 GROUP BY [my Disks Coefficients sub].[thier Disk ID], [my Disks Coefficients sub].coefficient ORDER BY [my Disks Coefficients sub].coefficient;
I then plugged this into a query in the WHERE clause using In (Select Top .....;); [changing the =1 condition to pick up the correct id from the emcompassing query]:-
SELECT [my Disks Coefficients].[my Disk ID], [my Disks Coefficients].[thier Disk ID], [my Disks Coefficients].coefficient FROM [my Disks Coefficients] WHERE [my Disks Coefficients].[thier Disk ID] In (SELECT TOP 32 [my Disks Coefficients sub].[thier Disk ID] FROM [my Disks Coefficients] AS [my Disks Coefficients sub] WHERE [my Disks Coefficients sub].[my Disk ID]=[my Disks Coefficients].[my Disk ID] GROUP BY [my Disks Coefficients sub].[thier Disk ID], [my Disks Coefficients sub].coefficient ORDER BY [my Disks Coefficients sub].coefficient;);
This runs fine but the the number of items returned is for each key is less than if I run the Top query by itself for each key seperately? So when I run it stand-alone for ID 1 I get 127 rows (there are many equal coefficients); when I run it as a sub-query I get only 121 rows for ID 1!
Anyone any ideas?
Martin
View 8 Replies
View Related
Sep 1, 2013
At most one record can be returned by this subquery. (Error 3354)
This is my SQL:
SELECT Students.[Student ID], Students.[Student Name]
FROM Students
WHERE (((Students.[Student ID])=(SELECT [Student ID]
FROM [Student_Sports]
WHERE [Sporting Team] = [Forms]![SV_Teams]![txtTeam])));
View 3 Replies
View Related
Nov 1, 2006
Hi,
I have made a query from different tables; however, my query is returning about 5 rows for each person because some fields in the query return more than 1 row.
Is there anyway to fix this problem?
Thank you,
B
View 3 Replies
View Related
Jun 2, 2013
I'm doing a subquery to select the top 5 of products for each supplier. The selection needs to be done randomly on the products for each supplier. For this I have made the following query (based on Allen Browne's example):
SELECT tblProducts_temp.SupplierID, tblProducts_temp.GTIN
FROM tblProducts_temp
GROUP BY tblProducts_temp.SupplierID, tblProducts_temp.GTIN
HAVING (((tblProducts_temp.GTIN) In (SELECT TOP 5 Dupe.GTIN
FROM tblProducts_temp AS Dupe
WHERE Dupe.SupplierID = tblProducts_temp.SupplierID
ORDER BY RND(Dupe.GTIN) DESC)))
ORDER BY tblProducts_temp.SupplierID, tblProducts_temp.GTIN;
The query returns a random number of products, but not a top 5. So for supplier X one time 3 products and the next time for supplier X 7 products.The query without the RND function, so just the top 5 works fine:
SELECT tblProducts_temp.SupplierID, tblProducts_temp.GTIN
FROM tblProducts_temp
GROUP BY tblProducts_temp.SupplierID, tblProducts_temp.GTIN
HAVING (((tblProducts_temp.GTIN) In (SELECT TOP 5 Dupe.GTIN
FROM tblProducts_temp AS Dupe
WHERE Dupe.SupplierID = tblProducts_temp.SupplierID
ORDER BY Dupe.GTIN DESC)))
ORDER BY tblProducts_temp.SupplierID, tblProducts_temp.GTIN;
View 2 Replies
View Related
Dec 3, 2004
Hello!
I have a form with a subquery on it that shows all of the records that the form is based upon. The subquery and form are linked already, so whatever record I change to on the form, the subquery will follow. The records are chronologically ordered by date in ascending order. Depending on what day the form is on, I want to be able to highlight the rows/records of that particular week automatically in the subquery. I was just wondering what method I can use to do the highlighting/selecting of the records if there is such a thing. Hope I was clear...THANKS! =)
G
View 1 Replies
View Related
Dec 3, 2013
We are developing a complaints tool. Each completed complaint needs to be signed off by 3 leads and I'm hoping to display the progress of this in a form. Obtaining the first is simple and I was able to do that relatively quickly. The subsequence ones are now giving me a headache as it doesn't seem I can reference the initial subquery field in the others.Here's what I have so far:
Code:
SELECT COMPLAINT_TBL.COMPLAINTID, COMPLAINT_TBL.CASENUMBER, COMPLAINT_TBL.COMPLAINTANTFORENAME, COMPLAINT_TBL.COMPLAINTANTSURNAME, BUSINESSUNIT_TBL.BUSINESSUNIT, COMPLAINT_TBL.FINALRESPONSEDATE,
(SELECT TOP 1 [SIGNOFF_TBL].[SIGNOFFDATE] FROM [SIGNOFF_TBL]
WHERE [SIGNOFF_TBL].[COMPLAINTID] = COMPLAINT_TBL.COMPLAINTID
ORDER BY [SIGNOFF_TBL].[SIGNOFFDATE] DESC) AS FIRSTSIGNOFF,
[code]....
View 6 Replies
View Related
Dec 27, 2013
I have a query that returns several records, typically 1 to 5. I need to print a label for each record returned by the query. Printing a label is no problem, but how do I print sequentally for each record in the query?
View 2 Replies
View Related
May 7, 2014
I have a table of accounts and a table of rates. There is a one-to-many relationship between them (i.e. each account can have multiple rates, each with their own - unique - effective date)
I'm trying to build a query which will show me all of the accounts in the accounts table and the most recent rate (based on the effective date) for each of those accounts.
This is as far as I've gotten with the SQL :
Code:
SELECT [tblAccounts].[AccountID], [tblAccounts].[AccountNumber], [tblAccounts].[AccountName], [LatestRate].[IntRate], [LatestRate].[EffectiveDate]
FROM [tblAccounts]
LEFT JOIN
(SELECT TOP 1 [tblRates].[AccountID], [tblRates].[IntRate], [tblRates].[EffectiveDate]
FROM [tblRates]
ORDER BY [tblRates].[EffectiveDate] DESC) AS LatestRate
ON [tblAccounts].[AccountID] = [LatestRate].[AccountID]
But this can't work because the [LatestRate] subquery can only ever return one record (i.e. the most recent rate across all of the accounts)
I need the most recent rate for each of the accounts in the main query
(FYI - I use an outer join as it is possible for no rate to be available in the rates table for a given account, in which case I want to return the null value rather than omit the account from the resulting dataset...)
View 2 Replies
View Related
Jun 26, 2007
Hi all. I've done a search for my problem, but its rather specific so I thought I'd just go ahead and post it.
I'm trying to set up a Verify type thing. A handful of users are able to "verify" the correct data in a form that has been inputted by other users. I want these "verifiers" to click a button on the main form and by doing this, all of the data in the form will be sent to a totally different table (I know this isn't efficient and you're not supposed to have the same data in 2 different tables, but it's the best thing to do in my situation). Right now I have a button that is tied to a Append query. It works, except for the fact that everytime someone hits the button it copies over every single record on the table again and again. So my small database of only 1000 records or so shot up to 2000 when the button was hit twice and 3000 when it was hit 3 times and so on.
Is there any way to append one record - specifically the record the user is currently accessing on the form?
View 8 Replies
View Related
Oct 8, 2013
I have a table that has records of accounts, actions taken, and operator ids. Unfortunately, the records are incomplete. The report was written poorly so that there is a row that contains data in all three fields for all subsequent rows there is only the action taken, no account or operator. So my table looks like that the records below. As you can imagine this means that I cannot write any useful queries on what happened on various accounts. How I can append the account number to every row that pertains to that account number?
Account
Action Taken
Operator ID
1234
Act1
1
Act2
Act3
Act4
1235
Act1
2
Act2
1236
Act1
3
Act2
Act3
View 5 Replies
View Related
Jul 6, 2015
It should be noted that this is a shared database with the BE on a network. I have a process that allows users to create an Agenda for a meeting. In order to make the process more efficient the user selects a drop down box which then prefills attendees for that meeting. All very simple really, until more than one user attempts to run the process.
The issue is that this process runs a couple of queries. One to filter the attendees and then another to combine this information with the agenda information which is then finally appended to the MASTER Data tbl.
Is there a way that I can stop users using this at the same time by either giving an alert to the new users saying please wait and defer the process until the current process has completed and then the new request starts.
View 1 Replies
View Related
Jun 17, 2015
After appending data in a table, I open a particular form. I want to display only the last record. I've added the code (DoCmd.GoToRecord , , acLast) to the On Load and On Open properties without success (opens first record).
View 14 Replies
View Related
Oct 10, 2007
I have a table of products and a table of ordersEach product requires multiple processes to completeCan I make a query that will lookup the products in the orders table and show a list of all the processes that need to be done to complete all the products on order?The bit I dont get is how can a query return multiple rows for each product?
View 3 Replies
View Related
Jul 19, 2005
Is it possible to add a row between rows on a form. I am creating a contact list containing phone numbers and groups. I dont want to sort the form out in ascending order, just by group order.
For example:
Joe Teacher (primary school) 12345
John Teacher (primary school) 67777
Ann Teacher (secondary school) 35555
Mary Teacher (secondary school) 388338
Sarah Nurse 373773
Tina Nurse 111111
Peter Footballer 199999
Rob Footballer 888888
Any ideas would be great :confused:
View 8 Replies
View Related
Aug 19, 2004
oh, finally I am close to what i need
I have the report in the included db. there are 2 problems though.
1
the subreport DOES sum the total for each outlet if there is one, BUT it includes a row for each outlet, therefore repeating up to 3 times.
ex:
if EN-02 and EN-05 have values 1 and 3 recorded on the same date then the report has the rows:
March 8, 2004 1 0 3
March 8, 2004 1 0 3
when it should only show 1 of the rows
and if there is a value from another date it includes it in this as well.
so how can i have this limited to the sum where the dates are the same.
2
how can I have it display "No flow" if there are no values instead of '0'
thanks for all your help in advance
~
View 5 Replies
View Related
Mar 19, 2015
I have attached a sample spreadsheet. Each store has a planned date which is calculated off the dates in column b and c. The second row is actual date.
As much of the data I have is in MS Access, I tried to use some extracts to appear in this format but no luck.
View 11 Replies
View Related
Mar 24, 2005
Hello all!
I have a database that needs to post records that are joined from three different sources into a table. The query is done, and I get about 1,489 records out in 4 different states.
What I need to do is make a table with these records. Furthermore, it must be separated by state, whereas if there are less than 1000 records for each state, it must insert blank lines until it reaches then next thousandth (sp?) row (i.e. 1001, 2001, etc.), and then start posting the next state.
For example, AZ has 420 records. There has to be 580 blank lines before the query can start posting the next state, CA. At row 1001, CA starts posting, but there are only 200 records for CA so there must be another 800 blank lines before moving on to CO at row 2001, etc. etc.
Anyone have any ideas on this? Thanks!
View 5 Replies
View Related
Jul 16, 2014
For each record in my database, there are observation periods which are recorded in the format dd/mm/yyyy hh:mm:ss, titles as follows
1st Obs Start
1st Obs End
2nd Obs Start
2nd Obs End
3rd Obs Start
3rd Obs End.
I have been asked to create a query that will quickly show how many obervation periods commenced in a particular month. What I am trying to do is create a column that will be named Obs Start, and another, Obs End. For each record ID, this would then show as follows:
ID......Obs Start.............Obs End........
1....[1st Obs Start].....[1st Obs End]....
1....[2nd Obs Start]....[2nd Obs End]....
2....[1st Obs Start].....[1st Obs End]....
2....[2nd Obs Start]....[2nd Obs End]....
2....[3rd Obs Start].....[3rd Obs End]....
3....[1st Obs Start].....[1st Obs End]....
4....[1st Obs Start].....[1st Obs End]....
etc.
I could then quickly count how many obs periods started within the desired month.
View 14 Replies
View Related
Feb 12, 2007
Can anyone tell me what is wrong with this complex query? It works fine without the highlighted subquery. The subquery works fine on its own. But they don't work together.
I think that I might not be able to call multiple results from a subquery but I'm not sure about that. Does any one know???
Any help will be much appreciated!
Thanks!
select k.site_id, s.name, t.date_opened,
(select concat(c.name_first,' ', c.name_last) as User from sitepack_approval sa
left join sitepack_approval_users spa on sa.approval_id=spa.approval_id
left join contacts c on spa.user_id=c.contact_id where sa.site_id=k.site_id and spa.timestamp is null
order by spa.level limit 1) as pending_approver,
(select sat.name from sitepack_approval sa left join sitepack_approval_types sat
on sa.approval_type_id=sat.approval_type_id where sa.site_id=k.site_id order by sa.approval_id desc limit 1)
as sitepack_type,
(select t.site_id, D.name AS Division, R.name AS Region, M.name AS Market,
concat(C1.name_first, " ",C1.name_last) AS RD,
concat(C2.name_first," ",C2.name_last) AS DD
FROM stores as t LEFT JOIN regions as M ON t.region_id = M.region_id
LEFT JOIN regions AS R ON M.parent_region_id = R.region_id
LEFT JOIN regions AS D ON R.parent_region_id = D.region_id
LEFT JOIN contacts AS C1 ON R.contact_id = C1.contact_id
LEFT JOIN contacts AS C2 ON D.contact_id = C2.contact_id) as site, Divsn, Reg, Mkt, RDs, DDs,
concat(cd.name_first,' ',cd.name_last) as 'DRE'
FROM sitepacks k LEFT JOIN sites s on k.site_id=s.site_id
LEFT JOIN stores t on k.site_id=t.site_id
LEFT JOIN contacts cd on k.dre_contact_id=cd.contact_id
WHERE status_id=(select status_id from sitepack_status where description='Approving' and sitepack_type <> 'Renewal')
and t.status_code <> 'DEAD'
and t.date_opened > now();
View 1 Replies
View Related
May 17, 2005
I can get the number of records to be returned but I want to run a condition if the records returned is zero. To do this, I need to put the number returned into a variable but I haven't been find a way.
For instance, this code does work:
SQL = "SELECT Count(*) AS Records FROM Table1 GROUP BY Table1.Quantity HAVING (((Table1.Quantity)=4));"
conDatabase.Execute SQL
But I want to store the count as a variable. What I want is something that look this (it doesn't work but I just want to give an idea what I'm looking for)
SQL = "SELECT Count(*) AS Records FROM Table1 GROUP BY Table1.Quantity HAVING (((Table1.Quantity)=4));"
Dim hold as Integer
hold = conDatabase.Execute SQL
If(hold = 0) Then
'tell them nothing returned
End If
So how can I go about this?
Update: I see that someone posted a solution a few threads down using queries which did work. Can I still still do the same thing with SQL strings?
scratch
View 2 Replies
View Related
Jan 16, 2006
I have a query that i run and now I am adding another column to provide a ETA for an order, when i specify a date I only get results that have that date and when I leave out the date I get too many results. Can someone please let me know how I can modify my query so that I get all the results with an ETA and also all the accounts that do not have an order placed.
Thanks,
Scott
View 2 Replies
View Related
Mar 17, 2007
Say I have a bunch of short dates like 2/12/2006 or 12/21/2005. What function should I use to get 2/12 and 12/21 returned? Datepart doesn't work ...
View 1 Replies
View Related
Aug 21, 2007
I'm using a very basic query
SELECT DRAWING_desc
FROM Drawing
WHERE DRAWING_desc Like '%L%'
I've got a table called Drawing, and a column in that table called Drawing_desc
I want all records returned that have the letter "L" in them.
When I run this query, I get nothing
If I replace the '%L%' with "*" it returns all records like you'd think it would.
What gives?
View 8 Replies
View Related
Dec 5, 2004
I am trying to create a Membership report that shows member activity over several months.
My problem is that the software that gives me the Member Activity does not report on accounts that were not used during that month
and some members do not come in every month.
I have a Member's Details table as well as individual months activity and have queries set to show the results of each month individually (these work, obviously)
The Reports I am trying to get from Access only show the activity of Members that have some movement every month, but totally skips members that are not present for 1 or more.
The report uses these queries but fails to report any member that is not in the tables for all months.
Example:
September
Rank Member FirstName LastName Activity
1 100 Andy Todd 200
October
Rank Member FirstName LastName Activity
November
Rank Member FirstName LastName Activity
5 100 Andy Todd 50
The report needs to show: Member FirstName LastName Sept.Rank Sept.Activity Oct.Rank Oct.Activity Nov.Rank Nov.Activity
but will not because there are no values for that member in October.
I am teaching myself Access as I go, so I am sure there is an easy solution.
Any help greatly appreciated.
Andy
View 1 Replies
View Related
Dec 20, 2012
I have an Access database set up with a table, several queries and forms (Weekly, Monthly, Quarterly, Pending). When I click on the any of the forms the table come up with rows of data just like it should. When I click on any of the rows instead of the data coming up so that I can edit it the entire Access database shuts down and then restarts. A backup version of the database is generated and it asks me to save it. I have verified that the forms are linked to the correct queries so I'm at a loss as to why this is occurring.
View 3 Replies
View Related