473,800 Members | 2,608 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple JOIN, INTERSECT query

Hi,

We are in the process of buying a new server to run mssql. However
before this as a tempory fix to using a msaccess backend i believe
through odbc i need to address the following issue:

SELECT ai.entry_date as CallTime,
ai.agent_login as AgentsLogin,
ai.campaign as MarketingCampai gn,
ai.agent_input2 as ProductsSold,
ai.first_name as Cust_FirstName,
ai.last_name as Cust_LastName,
ai.agent_input1 as Cust_PersonalNu mber,
ai.street_addre ss as Cust_AddressStr eet,
ai.city as Cust_AddressCit y,
ai.state as Cust_AddressSta te,
ai.zip as Cust_AddressZIP ,
rec.file_name as AgreementRecord ingFile
FROM agent_input ai, leads l, recordings rec
WHERE ai.whole_phone_ number = l.whole_phone_n umber AND
l.call_status = 1110 AND
rec.whole_phone _number = l.whole_phone_n umber AND
rec.last_name = l.last_name AND
rec.agent = ai.agent_login AND
rec.campaign = l.campaign AND
last_call_date between #04/24/2006 12:00 AM# and #04/25/2006 11:59 PM#
ORDER BY ai.agent_login, ai.entry_date

I want to make the recordings entry optional so the same results come
out whether it matches a recording or not. If it does i want it to
populate the AgreementRecord ingFile column above, if not just put a ''
as you would with '' as AgreementRecord File.

Does anyone know how you can do this, in a access based database system
using SQL through i believe ODBC?

Thanks

David

Apr 25 '06 #1
1 4117
David (da************ @gmail.com) writes:
We are in the process of buying a new server to run mssql. However
before this as a tempory fix to using a msaccess backend i believe
through odbc i need to address the following issue:

SELECT ai.entry_date as CallTime,
ai.agent_login as AgentsLogin,
ai.campaign as MarketingCampai gn,
ai.agent_input2 as ProductsSold,
ai.first_name as Cust_FirstName,
ai.last_name as Cust_LastName,
ai.agent_input1 as Cust_PersonalNu mber,
ai.street_addre ss as Cust_AddressStr eet,
ai.city as Cust_AddressCit y,
ai.state as Cust_AddressSta te,
ai.zip as Cust_AddressZIP ,
rec.file_name as AgreementRecord ingFile
FROM agent_input ai, leads l, recordings rec
WHERE ai.whole_phone_ number = l.whole_phone_n umber AND
l.call_status = 1110 AND
rec.whole_phone _number = l.whole_phone_n umber AND
rec.last_name = l.last_name AND
rec.agent = ai.agent_login AND
rec.campaign = l.campaign AND
last_call_date between #04/24/2006 12:00 AM# and #04/25/2006 11:59 PM#
ORDER BY ai.agent_login, ai.entry_date

I want to make the recordings entry optional so the same results come
out whether it matches a recording or not. If it does i want it to
populate the AgreementRecord ingFile column above, if not just put a ''
as you would with '' as AgreementRecord File.


If I understand this correcly you need an outer join:
SELECT ai.entry_date as CallTime,
ai.agent_login as AgentsLogin,
ai.campaign as MarketingCampai gn,
ai.agent_input2 as ProductsSold,
ai.first_name as Cust_FirstName,
ai.last_name as Cust_LastName,
ai.agent_input1 as Cust_PersonalNu mber,
ai.street_addre ss as Cust_AddressStr eet,
ai.city as Cust_AddressCit y,
ai.state as Cust_AddressSta te,
ai.zip as Cust_AddressZIP ,
coalesec(rec.fi le_name, '') as AgreementRecord ingFile
FROM agent_input ai
JOIN leads l ON ai.whole_phone_ number = l.whole_phone_n umber
LEFT JOIN recordings rec ON
rec.whole_phone _number = l.whole_phone_n umber AND
rec.last_name = l.last_name AND
rec.agent = ai.agent_login AND
rec.campaign = l.campaign
WHERE l.call_status = 1110 AND
last_call_date >= '20060424' AND
last_call_date < '20060426'
ORDER BY ai.agent_login, ai.entry_date

Two disclaimers:

1) I don't know from which table last_call_date comes from. I've assumed
that it comes from agent_input or leads. If it comes from recordings,
the above query is not likely to be correct.

2) The syntax works on SQL Server, because that is all I know. If you want
syntax that works on Access, ask comp.databases. ms-access.

--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Apr 25 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
39961
by: Nick | last post by:
I have three tables books (id, title, author) authors (id, name) authors_groups (author_id, group_id) I have a query that searches for authors who must be in a least one subgroup of two groups. I hope that makes sense. Here are some examples im working on...
1
714
by: sunaina | last post by:
I am doing the following query using intersect but gives me an error 'error in sql syntax. I tried using join as well but gives me similar error. In the following code still has intersect just to show exactly what I want to do. My query in mysql console is working without using intersect or join. $query_objects = ""; for ($i=0; $i<$num_questions; $i++) { if ($i != 0)
7
11196
by: steve | last post by:
Can you join two tables across different servers in mySQL, or am I dreaming of Oracle? -- Posted using the http://www.dbforumz.com interface, at author's request Articles individually checked for conformance to usenet standards Topic URL: http://www.dbforumz.com/mySQL-Join-servers-ftopict225285.html Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbforumz.com/eform.php?p=777346
1
3647
by: j.mandala | last post by:
I created a simple link between two tables in a query. TableA has Social Security numbers stored as Long Integer Data. (I imported this table). The Join is between these two fields Table Field Data Type ------------------------------------------ TableA ClientNumA Long Integer TableB CliNumB String
2
2398
by: Fendi Baba | last post by:
I created a person table with various fields such as Suffix, Salutation, etc, Some of these fields may not be mandatory for example suffix. In the actual table itself, I only have a field for suffix ID where 1=Phd, 2= MD. To display all of these to the user, I created a form with an underlying query. The problem I am encountering is this, when we have an empty field, for example where ID="", the query returns nothing. How do i work around...
9
19161
by: Emin | last post by:
Dear Experts, I have a fairly simple query in which adding a where clause slows things down by at least a factor of 100. The following is the slow version of the query ------------------------- SELECT * FROM ( Select x.event_date From x FULL OUTER JOIN y ON x.event_date = y.event_date
1
1506
by: Xpertboy | last post by:
i am trying to execute following code in asp var strSQL1="select Model from Phones where Brand='"+ brand +"'"; var strSQL2="select Model from Phones where Model='"+ model +"'"; var strSQL3="select Model from Phones where Camera='"+ camera +"'"; var strSQL=strSQL1+" intersect "+ strSQL2+" intersect "+strSQL3 conn.Execute(strSQL); but its giving error in executing query... basically i want intersect of 2 or more features using...
3
3504
by: bzb | last post by:
hi ALL, I have a situation to use INTERSECT in my query, but INTERSECT is not supported in "mysql 4.1.15". Can anyone explain me how to tackle this problem..... ! Also, is there any version of mysql which allows the usage of INTERSECT ? Thank you ! bzb...
1
2682
by: b00010783 | last post by:
Hi all, I have the table below. +--------+---------+-------------+--------------------------------+-------+----+ | parent | country | city | hotel | stars | id | +--------+---------+-------------+--------------------------------+-------+----+
0
9694
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9553
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10039
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9095
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7584
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6824
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5477
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5612
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2953
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.