Can Someone Please Explain Basic Query Logic To Me?
May 11, 2006
I am not sure if I understand this...
I have MainTable, on which I base MainForm. I would like to have MainForm show only the records that have a null value in CertainField. If I write NullQuery to select only those records, can I redirect MainForm to NullQuery? Well, I know I can do that... but how does MainTable get updated with new records if MainForm is based on NullQuery????
Any help is greatly appreciated.
Tom
View Replies
ADVERTISEMENT
Oct 17, 2006
Hi all,
I was recently asked to rewrite some stuff and i was wondering if the query below can be expressed with just ( SELECT, FROM, WHERE, GROUP BY ) Instead of JOIN.
Someone else wrote the query below and Joins always confuse me ...
Thanks in advance
SELECT Grpoffic.CODE, Evoter.precinct, Evoter.grp, IIf(evoter.style Is Not Null,evoter.style,evoter.[activator code]) AS ballot, Evoter.party, Evoter.[date voted] AS [voted date], Evoter.certnum AS [voter id], Evoter.name, Evoter.address, Evoter.[ev location] AS [Location voted], Vote_status.status, AB_CODE_reason.reason AS [absentee reason]
FROM Vote_status, AB_CODE_reason RIGHT JOIN (Evoter INNER JOIN Grpoffic ON (Evoter.precinct = Grpoffic.pct) AND (Evoter.grp = Grpoffic.grp)) ON AB_CODE_reason.code = Evoter.reason
ORDER BY Grpoffic.CODE, Evoter.precinct, Evoter.grp, Evoter.name;
View 1 Replies
View Related
Mar 29, 2008
Hi all!, i would really appriciate it if you could help me out. I have this complex query... in one table i have dates and costs associated that show when fuel was put into the system
such as:
1/1/2008 -- $200
1/20/2008 - $100
1/25/2008 - $150
I then have another table that has data when fuel was taken out of the system
such as:
1/2/2008 -- ($50)
1/3/2008 -- ($20)
1/4/2008 -- ($10)
what i need is a query that is able to show a running tab on the fuel tank and how much fuel is in it...
so for example if it could spit out a result such as
1/1/2008 -- $200
1/2/2008 -- $150
1/3/2008 -- $130
1/4/2008 -- $120
If this is convoluted i can upload a little database..
Thanks! (Here is the current query i am using but its not working right.
SELECT DatePart("yyyy",[purchase_Date]) AS AYear, DatePart("m",[Purchase_Date]) AS AMonth, DatePart("d",[Purchase_Date]) AS ADay, DSum("gallons_purchased","purchase_fuel_tbl","DatePart('d', [purchase_Date])<=" & [ADay] & " And DatePart('m',
[purchase_Date])<=" & [AMonth] & " And DatePart('yyyy',
[purchase_Date])<=" & [AYear] & "") AS RunTot, fuel_use_tbl.fuel_date, fuel_use_tbl.external_ID, fuel_use_tbl.gallons, [RunTot]-[fuel_use_tbl].[gallons] AS cur_Value
FROM (tank_tbl RIGHT JOIN purchase_fuel_tbl ON tank_tbl.tank_ID = purchase_fuel_tbl.tank_ID) LEFT JOIN fuel_use_tbl ON tank_tbl.tank_ID = fuel_use_tbl.tank_ID
GROUP BY DatePart("yyyy",[purchase_Date]), DatePart("m",[Purchase_Date]), DatePart("d",[Purchase_Date]), fuel_use_tbl.fuel_date, fuel_use_tbl.external_ID, fuel_use_tbl.gallons
ORDER BY DatePart("yyyy",[purchase_Date]), DatePart("m",[Purchase_Date]), DatePart("d",[Purchase_Date]);
View 14 Replies
View Related
Oct 18, 2006
Access is making my brain hurt - can anybody please help?
Here's what I have and what I am trying to get it to do...
I have a table, maba_registrations, into which students are entered according to which course they are doing in which semester - eg -
autonumber student_id course_code semester year
1 1 A123 1 2006
2 2 A124 1 2006
3 2 A124 2 2006
4 2 A126 1 2006
5 3 A132 1 2006
What I need to do is to pull four subsets of data out of this table -
1) A unique list of courses that student x is taking in semester 1 (only) of a given year
2) A unique list of courses that student x is taking in semester 2 (only) of a given year
3) A unique list of courses that student x is taking over 2 semesters (both semester 1 and semester 2 of a given year)
4) A unique list of courses that student x is taking over 2 semesters (semester 2 of a given year and semester 1 of the following year)
Obviously there should be no overlap... and that's where I get a bit stuck
I can craft a simple query that will show me the courses a student is taking in semester 1 of a given year, but I cannot figure out how to get it to exclude those courses which are also still being taken in semester 2. In the above example, the query pulls out records 2 and 4 for student 2; I only want record 4.
I think what I need is to have 2 queries -
a) pulls out all courses for student x in semester 1 for the current year
b) pulls out all courses for student x in semester 2 for the current year
- and then subtract the results of query (b) from query (a) (ie remove the rows that are matched). Is there any way to do something like that?
Or is there a simple part of query syntax that I can use to make a query that just says "pull out all the courses for student x where semester=1 and there is no row for this course and this student where semester=2"?
Any ideas would be hugely appreciated!
View 4 Replies
View Related
May 4, 2007
Hey guys, I'm a little lost in my logic here for some reason.
I have a table that has 6 dates. I'll label them as 1 to 6.
Date 1 > Date 2 > Date 3 > Date 4 > Date 5 > Date 6.
I would like to run a query to ensure that this holds true. Can anyone give me a little help on this?
Do I have to do an individual compare from 1 field to the 5 other fields 6 times? for example
Select if
Date 1 < Date 2
OR
Date 1 < Date 3
OR
Date 1 < Date 4
etc etc.?
View 5 Replies
View Related
Apr 4, 2008
I realize my newbness shows here...
Im trying to run a query that looks in a table to see if product a and product b were purchased and then return the id but i never get any data, and I know there are some results that should be showing up. If I remove either one of the products it returns data but not when both are requested. here's the query:
SELECT [Copy Of data].id, data.purchase_product, data.purchase_product
FROM data INNER JOIN [Copy Of data] ON data.email = [Copy Of data].email
WHERE (((data.purchase_product)="ProdA") AND ((data.purchase_product)="ProdB"));
what am i not getting?
View 5 Replies
View Related
Aug 24, 2007
I am building a database that will tell the company what items to dispatch to the customer first. It’s a food company. So getting products out on time is important. I will try explain it. Say the food company makes a batch of 30 apple tarts. This collection of products has a set batch number with all the relevant information attached. For exampleBatch no 4457 - qty 30 - created 10/10/07 - use by 10/11/07 Batch no 4458 - qty 30 - created 11/10/07 - use by 11/11/07Now lets say customer (joe Bloggs) orders 35 apple tartsThe food company wants to take all the first batch (4457) and 5 from the second batch (4458) The will have an order sheet with the followingApple tart batch 4457 - 30Apple tart batch 4458 - 5 After the order is gathered it will be given an order number of say order 8897The company can now go back and look at order 8897 and see what was shipped in that order and what the batch numbers where for all products. Any help would be greatly appreciatedAlan
View 14 Replies
View Related
Oct 8, 2014
I'm trying to create a new field based on two existing fields as part of a select query. Two tables in the query each have a "HOSPITAL" field which is an indicator for "Y" or "N" for each department (in the DEPTLOOKUP table) and for each facility (in the Facility Lookup table). I want to create a field whereby a new indicator is created so that a Y is given for each record only where the facility and department HOSPITAL indicator field is both "Y". I have attached a word document that has a screenshot of the query in design view as well as the access sql code.
View 3 Replies
View Related
Apr 6, 2007
Can someone explain what the following code does.Thanks in advance
Set dbUser = DBEngine.Workspaces(0).Databases(0)
Set rsUser = dbUser.OpenRecordset("SELECT User.UserName FROM [User]WHERE (((User.UserName)='" + txtUserName + "'))")
View 1 Replies
View Related
Mar 6, 2008
Month Number: Mid([Date],4,2)
I also have the SQL that goes with the query:
SELECT Mid([Date],4,2) AS [Month Number], Count(tblOrders.Order_Number) AS CountOfOrders, Sum(tblBikes.Price) AS SumOfPrice, Format([Date],"mmmm") AS [Month Name]
FROM tblOrders INNER JOIN (tblBikes INNER JOIN [Order/Product] ON tblBikes.Model_Number = [Order/Product].Model_Number) ON tblOrders.Order_Number = [Order/Product].Order_Number
GROUP BY Mid([Date],4,2), Format([Date],"mmmm");
:confused:
View 6 Replies
View Related
Aug 11, 2005
Hi expert. could any one explain this code for me. I do not understand some parts of it. I know the output but not some parts of the code.Thanks
Code:Private Sub processButton_Click() Dim fso As New Scripting.FileSystemObject <------ Dim io As Scripting.TextStream <------ Dim db As DAO.Database Dim rst As DAO.Recordset Dim fld As DAO.Field '''Declreaing our variables Dim strBase As String Dim strInsert As String Dim strFields As String Dim strValues As String Dim strTemp As String Dim strFile As String Dim strName As String Set db = CurrentDb() Set rst = db.OpenRecordset(Me![ComboBox]) strBase = "INSERT INTO " & Me![ComboBox] & "({%1}) VALUES ({%2})" <------ strName = "c:" & Me!ComboBox & " Data.sql" With rst <------ While Not .EOF strValues = "" <------ If Len(strFields) = 0 Then For Each fld In .Fields If Len(strFields) > 0 Then strFields = strFields & "," & fld.Name & "" Else '''strFields = "[" & fld.Name & "]" strFields = "" & fld.Name & "" End If Next fld strInsert = Replace(strBase, "{%1}", strFields) End If For Each fld In .Fields If Len(strValues) > 0 Then strValues = strValues & "," End If If IsNull(fld.Value) Then strValues = strValues & "null" Else v = fld.Value Select Case fld.Type Case dbMemo, dbText, dbChar strValues = strValues & "'" & v & "'" Case dbDate strValues = strValues & "#" & v & "#" Case Else strValues = strValues & v End Select End If Next fld strTemp = Replace(strInsert, "{%2}", strValues) strFile = strFile & strTemp & vbNewLine .MoveNext Wend rst.Close End With If Len(strFile) > 0 Then Set io = fso.CreateTextFile(strName) io.Write strFile io.Close End If End Sub
View 3 Replies
View Related
Oct 11, 2006
I am trying to figure out how this code actually works. In the Field I see the following code:
IIf(Weekday([CollectionDate]-4)=1,[CollectionDate]-6,IIf(Weekday([CollectionDate]-4)=7,[CollectionDate]-5,[CollectionDate]-4))
In the Criteria I see: Like Date()
I know what the "LIke Date() does but what im trying to figure out what is the connection to the above....
Any Help would be greatly greatly appreciated!
View 1 Replies
View Related
Sep 20, 2005
I have written a basic query that looks at the date field, department field and cost the cost field on a table. What I would like is a form that you can chose a date (19/09/2005) and a it looks at the table and calculates the total sum of money for each department for this date. Ie.
Date: 19/09/2005
Dept 1 = £123.00
Dept 2 = £1234.00
Dept 3 = £123.00
Dept 4 = £1234.00
Dept 5 = £123.00
Dept 6 = £1234.00
I can get the query to work but only 1 department at a time. Any ideas?
I have attached the DB
Thanks
D
View 6 Replies
View Related
May 22, 2006
Hello all This is a pretty basic query I guess but I am having trouble solving this.. Can anyone help plsssssssss.
I have two tables
Table1
Code Serial_No Amount1 Amount2
1 ABC 100 200
1 ABC 720 220
4 ABC 150 112
9 PQR 11 25
9 ZZZ 122 44
9 ZZZ 1250 42
Table2
Code Serial_No Amount1 Amount2
1 ABC 24 20
1 PPP 72 22
4 ABC 15 12
9 PQR 11 54
9 ZZZ 22 44
9 ZZZ 150 99
and total of the amount as 844 and 440
I have write a query to select only the Code common to both the tables and add total of amounts for these codes. For eg. I want rows
Outpput
1 ABC 100 200
1 ABC 720 220
1 ABC 24 20
Thanks in advance
View 4 Replies
View Related
Sep 5, 2006
I saw this code and was wondering how does it actually work?
I saw it in/connected to a textbox.
Private Sub savetime_BeforeUpdate(Cancel As Integer)
End Sub
View 1 Replies
View Related
Sep 20, 2005
OK, here's the deal. I have two data tables, one of which holds many types of customer information and has a very large number of records, including, name, address, phone, and email. The other table contains only email addresses. Each email in the second, smaller table corresponds to a record in the larger list , by virtue of both records sharing the same email address (primary key?). I need to be able to take a short list of email addresses from one table and produce all of the records from the larger table that have corresponding email addys, essentially. Can somebody shed some light on how I can structure a query to solve this dilemma? Sorry for the newb question, just getting started out using db's.. Thanks!
View 1 Replies
View Related
Aug 10, 2006
Hello, i have a small database thats purpose is to show when a book has been returned to me. I am recording the date that books are loaned out. Books are loaned for a 2 week period. I dont know if it would be easier to just manually put in the date that books should be returned (so that means just manually calculate what the date will be 2 weeks later). The reason for this is because i want a query that shows when the date has passed and how many days overdue the book is. Would this be difficult to achieve? What i was thinking is a query that calculates when the 2 week period is up and adds the unique number for book in a report.
Can anyone help?
Thanks,
Marley.
View 2 Replies
View Related
Nov 28, 2006
i have a very basic query question that i can't seem to figure out.
i have two tables that have a one-to-many relationship - one has patient ID's, and the second table has test results for each patient.
i would like to query for all positive test results - however, if a patient EVER had a positive result, i want ALL records for that patient returned.
thus, if a record in the "many" table meets a particular criterion, i want it to return all records with the same ID. does that make sense?
thanks in advance...
View 6 Replies
View Related
Jul 11, 2007
hi..
quick question...
i want to update all the records in a certain field..
to make the first letter of each word a capital
to make every letter a capital
i know how to make un update query, what to i put in the criteria if the field is called
field1
cheers
View 5 Replies
View Related
Dec 1, 2005
Hi all
I have a financial database that gets downloaded transactions off the internet from our accounts. The problem is that the transaction payer/payee is not always unique and needs to be classified. This is easy done using If statements but I really want to enter parts of the string into a table and have a query return a category for this payer/payee. Example:
I want this: AUTO ONE CLARKSON CLARKSON WA AU006495
to be recognised as: car parts
or with this tranaction:
CLARKSON MINI MART CLARKSON553908
look for "mini mart" and return supermarket
This step will make classifying transactions a lot simpler and user friendly.
thanks
View 3 Replies
View Related
Jul 16, 2005
Let see if I can explain my goal. I've been fighting with this for some time with no resolve. In the included DB has a table that represents the fields that will be queried in the real DB. It shows records of one of many employees that were "tested" (shopped) on a date and whether it was a successfull shop or not. My goal is in three parts.
1)A query that goes through each employee and returns the records with the check box in SuccessYes checked (Yes) back to the last unchecked box, not including the unchecked box. In the example given the last (most recent) 5 records would be returned. If the shop of date 1/18/2005 was not checked, it would only return the last 2 records. Basically, I'm looking for a way to have a report that shows everyone's current successes in a row. It could be any number.
2)A query very similar but it returns only those employees that have the current successes in a row totalling 5 and where the field "Award5_Paid" is NOT checked (they have not been paid their reward). From there it should be easy to do one for the 10 in a row.
3)If I've got a form open (or...?) where I can place a command button, that when clicked, it appends the selected records with checks in the appropriate boxes for being paid. Example: If a set of employees come up in the query with 5 successfull shops in a row because the "Award5_Paid" field is unchecked, then I need to pay them. Click the button and the Award5_Paid field gets checked in THOSE RECORDS ONLY so that the next time I run the query, they won't show up and get paid twice. Issue? What's the coding or SQL or ??? that's run when clicked.
I hope that makes sense. I've been running around in circle trying to figure this one out. Maybe it can't be done, but if it can, I know some of you know how.
As always, thanks for the assistance.
-Jim
View 3 Replies
View Related
Jun 5, 2006
Hi All,
I have two tables; "Section_Failure_Mode" and "Risk_Assessment". They are linked by a common field called section_failure_mode_id. I would like to write a query where you can delete every record in "Risk_Assessment" where the checkbox (called Selected) is not selected (i.e. equal to 0) in the table "Section_Failure_Mode". However, I do not want any records to be deleted from "Section_Failure_Mode", only from "Risk_Assessment".
I have put a link to the screen cap of the query I have tried below. Is this the correct way to do it?
13797
Best Regards,
Aaron
View 1 Replies
View Related
Sep 18, 2006
I have an access Query(named newSerial) :
SELECT TOP 1 (Productbase.Serialnumber+1) AS Expr1 FROM ProductBase
ORDER BY (Productbase.Serialnumber+1) DESC;
I want to access this new value. Its not a key since an autonumber may be any number. When I create a new product. How do I get this value inside a form?
It works fine when clicking on it. But if I use an unbound box I get 1 as result and not like 76067 which it should be. If I click the query in access it works fine and show 76067.
I tried:
outbox=Expr1
' gives null
'or
outbox=[newserial].[Expr1]
' which gives "Access cant find the field "|" refered to you in your expression"
What should I write? Whats the correct expression?
View 7 Replies
View Related
Sep 10, 2004
Is it possible to use a value on an Access driven form as a parameter in a pass through query?
View 4 Replies
View Related
Oct 20, 2004
Hello,
I am hoping someone might be able to help me out. I am trying to create a delete query in VB for access.
I have managed to get it to run the delete query, but I would like to program in the responses to the following questions:
"You are about to run a delete query that will modify data in your table. Are you sure.... Yes"
"You are about to delete X row(s) from the specified table. Yes"
Here is what I have so far:
Private Sub Command32_Click()
DoCmd.OpenQuery "DELETEQUERY", acViewNormal, acEdit
End Sub
Does anyone know how to do this???
Thanks,
Jason
View 2 Replies
View Related
Sep 16, 2005
Hi, i know i have done this before but its been so long and i know its real simple so here goes:
Say i have a record in a table and i want to add records to that record in another table does simply creating a relationship between the two tables make sure the information is relevant to that record and how do i add more than 1 tables information to a form so i could show the record from the first table and say all of that persons orders from another table?
Thanks for your assistance
Alex
View 1 Replies
View Related