473,395 Members | 2,446 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Writing a Query based on times in two different tables

Ok. Another tricky Access question. Same database, different querry.

I have a table called tbl_Responses and my tbl_Airing…similar to my question about linking Airings to Rates, I now need to link Airings to Responses.

For example, an ad airs on 2/12/2007 at 7:05am,10:20am, 1:45pm, 3:55pm, 8:20pm(this data will be stored on the Airing table). From that Airing, I get 34 responses with differing times through out the day. Is there a way to link the response to which Airing it came from? The threshold for the link between the Response and the Airing will be 30 mins, after 30 minutes it is considered “Unsourced”—which means we are unable to tell which Airing the Response belongs to.

In my Response table I have the following headers and info:

Station
Trans Date (date of Response)
Trans Time (time of Response)


In my Airing table I have the following headers and info:

Station
DoA (Date of Airing)
ToA (Time of Airing)

Any help you can give would be greatly appreciated!!!

Thanks!
Feb 13 '07 #1
9 1662
Rabbit
12,516 Expert Mod 8TB
My question is what happens to the response if there's an airing schedule as follows.

Ad A airs on Station KWOD at 7:05 AM
Ad B airs on Station KLCG at 7:05 AM
Ad C airs on Station KWOD at 7:08 AM

What I'm wondering is if you'll need to add fields in your Responses table to link it to your Airing table such as an Ad ID and Station ID.
Feb 13 '07 #2
My question is what happens to the response if there's an airing schedule as follows.

Ad A airs on Station KWOD at 7:05 AM
Ad B airs on Station KLCG at 7:05 AM
Ad C airs on Station KWOD at 7:08 AM

What I'm wondering is if you'll need to add fields in your Responses table to link it to your Airing table such as an Ad ID and Station ID.

You think of EVERYTHING! =)

Actually, there will only be one Ad running per station, however, I will need to link the Station on the Airing table to the Station on the Responses table. They will always be in the same format: (KDWB-AM or WLS-AM...3 or 4 letters and AM/FM).

Thanks!!! You are such a great help.
Feb 13 '07 #3
Rabbit
12,516 Expert Mod 8TB
You're more than welcome.
Feb 13 '07 #4
You're more than welcome.

=)

So I will need to link tbl_Responses and tbl_Airing by Station and by Date, then do an IF statement to link my response times to my airing times. I wrote this:

Expand|Select|Wrap|Line Numbers
  1. SELECT tbl_Responses.Station,
  2.        tbl_Responses.[Trans Date],
  3.        tbl_Responses.[Trans Time],
  4.        IIf(([tbl_Airing.ToA]-[tbl_Responses.Trans Time])<=#12/30/1899 0:30:0#,[tbl_Airing.ToA],“unsourced”) AS Expr1,
  5.        tbl_Airing.[Length of Spot],
  6.        tbl_Airing.[Type of Read],
  7.        tbl_Airing.[Aired Offer]
  8. FROM tbl_Airing INNER JOIN tbl_Responses
  9.   ON (tbl_Airing.DoA = tbl_Responses.[Trans Date])
  10.  AND (tbl_Airing.Station = tbl_Responses.Station);
However it's not working and giving me back way too many records!
Feb 13 '07 #5
Rabbit
12,516 Expert Mod 8TB
Here's what's happening. If you have multiple records with the same Date of Airing and Station but with different times. And then you have different responses with the same Date of Response and Station. Then with an inner join, you're linking every airing with every response. So you get [# of Airings] * [# of responses] records.

My question is if you need any information from unsourced responses. If not, then in the criteria for Expr1, I'd filter out the "unsourced".

Here's another problem. If you have an airing at 7 AM and another airing at 7:15 AM, then the response would be linked to both airings.

If either of these are an issue, the only way to get around this is to use ToA in the Response table as an Airing ID to link them.

Also, your syntax should be:
Expand|Select|Wrap|Line Numbers
  1. IIf((tbl_Airing.[Trans Time]-tbl_Responses.[ToA])<=#12/30/1899 0:30:0#,[
Assuming that Trans Time will be later than the ToA.
Feb 13 '07 #6
Here's what's happening. If you have multiple records with the same Date of Airing and Station but with different times. And then you have different responses with the same Date of Response and Station. Then with an inner join, you're linking every airing with every response. So you get [# of Airings] * [# of responses] records.

My question is if you need any information from unsourced responses. If not, then in the criteria for Expr1, I'd filter out the "unsourced".

Here's another problem. If you have an airing at 7 AM and another airing at 7:15 AM, then the response would be linked to both airings.

If either of these are an issue, the only way to get around this is to use ToA in the Response table as an Airing ID to link them.

Also, your syntax should be:
Expand|Select|Wrap|Line Numbers
  1. IIf((tbl_Airing.[Trans Time]-tbl_Responses.[ToA])<=#12/30/1899 0:30:0#,[
Assuming that Trans Time will be later than the ToA.

Unfortunately, I do need the "Unsourced" information. I need to see how many responses are considered "unsourced. The response being linked to both airings is not going to be an issue. We will never have 2 airings that close to each other. So here is my second attempt at SQL:

Expand|Select|Wrap|Line Numbers
  1. IIf((tbl_Airing.Station = tbl_Responses.Station), And (tbl_Airing.[DoA] = tbl_Responses.[Trans Date]), (tbl_Airing.[ToA]-tbl_Responses.[Trans Time])<=#12/30/1899 0:30:0#,tbl_Airing.[ToA],"unsourced")
Of course, it's still not working...but I feel like I'm really close!
Feb 13 '07 #7
Rabbit
12,516 Expert Mod 8TB
Disregarding the incorrect syntax of the iif, you have extra commas that don't belong in there, this runs into the same problem as before. Here's the problem.

If you have:
Expand|Select|Wrap|Line Numbers
  1. Airings Table
  2. Station  DoA  ToA
  3. KWOD  1/1/2007  7:00AM
  4. KWOD  1/1/2007  7:00PM
  5.  
  6. Responses Table
  7. Station  DoR  ToR
  8. KWOD  1/1/2007  7:15AM
  9. KWOD  1/1/2007  7:18PM
  10.  
  11. What you get is
  12. Station  DoA  ToA  ToR  Expr1
  13. KWOD  1/1/2007  7:00AM  7:15AM  7:00AM
  14. KWOD  1/1/2007  7:00PM  7:15AM  Unsourced
  15. KWOD  1/1/2007  7:00AM  7:18PM  Unsourced
  16. KWOD  1/1/2007  7:00PM  7:18PM  7:00PM
  17.  
Now compound this problem by the number of Stations you have and by the number of airings you have per day on the same station.

I'm thinking you may need to keep the query the way it was in the beginning and then run a second query on it to remove all "unsourced" records that aren't really unsourced. Perhaps:

Expand|Select|Wrap|Line Numbers
  1. Expr2: iif(Expr1 = "unsourced", iif(Dcount("*", "qry1", "Station = '" & Station & "' AND DoA = " & DoA & " AND ToR = " & ToR & " AND Expr1 <> 'unsourced'") > 0, "", Expr1), Expr1)
This will check if Expr1 is unsourced. If it's unsourced, it will count to see if there are any records with the same Station, Date of Airing, and Time of Response that is sourced. If there is such a record, it will return a null string. If not, it will return "unsourced". And if Expr1 is sourced in the first place, it will just return Expr1 which is the ToA. And then, you just filter out the null strings.

Another problem, your expr1 field will be considered a string field because you return "unsourced" for some of the records. Dates/Times are stored as a number signifying the difference from an arbitrary date. What you will end up seeing is that number, i.e. 7 for 7 days from the chosen date. If the chosen date is 1/1/2007 then in Expr1 you will see 7 rather than 1/8/2007.
Feb 13 '07 #8
Disregarding the incorrect syntax of the iif, you have extra commas that don't belong in there, this runs into the same problem as before. Here's the problem.

If you have:
Expand|Select|Wrap|Line Numbers
  1. Airings Table
  2. Station  DoA  ToA
  3. KWOD  1/1/2007  7:00AM
  4. KWOD  1/1/2007  7:00PM
  5.  
  6. Responses Table
  7. Station  DoR  ToR
  8. KWOD  1/1/2007  7:15AM
  9. KWOD  1/1/2007  7:18PM
  10.  
  11. What you get is
  12. Station  DoA  ToA  ToR  Expr1
  13. KWOD  1/1/2007  7:00AM  7:15AM  7:00AM
  14. KWOD  1/1/2007  7:00PM  7:15AM  Unsourced
  15. KWOD  1/1/2007  7:00AM  7:18PM  Unsourced
  16. KWOD  1/1/2007  7:00PM  7:18PM  7:00PM
  17.  
Now compound this problem by the number of Stations you have and by the number of airings you have per day on the same station.

I'm thinking you may need to keep the query the way it was in the beginning and then run a second query on it to remove all "unsourced" records that aren't really unsourced. Perhaps:

Expand|Select|Wrap|Line Numbers
  1. Expr2: iif(Expr1 = "unsourced", iif(Dcount("*", "qry1", "Station = '" & Station & "' AND DoA = " & DoA & " AND ToR = " & ToR & " AND Expr1 <> 'unsourced'") > 0, "", Expr1), Expr1)
This will check if Expr1 is unsourced. If it's unsourced, it will count to see if there are any records with the same Station, Date of Airing, and Time of Response that is sourced. If there is such a record, it will return a null string. If not, it will return "unsourced". And if Expr1 is sourced in the first place, it will just return Expr1 which is the ToA. And then, you just filter out the null strings.

Another problem, your expr1 field will be considered a string field because you return "unsourced" for some of the records. Dates/Times are stored as a number signifying the difference from an arbitrary date. What you will end up seeing is that number, i.e. 7 for 7 days from the chosen date. If the chosen date is 1/1/2007 then in Expr1 you will see 7 rather than 1/8/2007.

Thank you!!! Sorry for the delay! I just saw this now!
Feb 26 '07 #9
Rabbit
12,516 Expert Mod 8TB
Not a problem. Let us know how you do and if you have any more problems.
Feb 26 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: MAX SMITH | last post by:
I'm a newbie to Access and am having trouble understanding the logic behind queries. I have 2 tables, 1 for stock in and 1 for stock out. I have joined these in a union query. the fields I have...
8
by: jquest | last post by:
Hi Again; I have had help from this group before and want to thank everyone, especially PCDatasheet. My database includes a field called HomePhone, it uses the (xxx)xxx-xxx format to include...
6
by: Brian | last post by:
Hello, Basically, I'm running a query on a form's activation, and I'd like to have the results of the query be placed into other fields on the same form automatically. Does anybody know how...
3
by: Serious_Practitioner | last post by:
Good day, and thank you in advance for any assistance you can provide. I have a table in an Access 2000 .mdb file, and I've run into something odd and insolvable, at least for me. The database is...
2
by: Jimmy Stewart | last post by:
Ok, I'm trying to write a query that is starting to wear me down. What I'm trying to do is create a year end report that gets sent to all of my customers who meet two criteria. One they are...
3
by: comp_databases_ms-sqlserver | last post by:
This post is related to SQL server 2000 and SQL Server 2005 all editions. Many of my stored procedures create temporary tables in the code. I want to find a way to find the query plan for these...
4
by: dancole42 | last post by:
So I have an invoicing database based on two main forms: Orders and OrderLines. Orders has fields like: OrderID BillingMethod OrderDate CreditCard CCExp OrdSubTotal ShippingCharge
8
geolemon
by: geolemon | last post by:
I'm trying to perform an update, and I can't avoid this error - I've tried this query what must be 5 different very fundamentally different ways now. Arg. I used to be a DBA in large DB2 and SQL...
2
by: existential.philosophy | last post by:
This is a new problem for me: I have some queries that open very slowly in design view. My benchmark query takes about 20 minutes to open in design view. That same query takes about 20 minutes...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.