473,689 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Select ContactID if field doesn't have a specific value

11 New Member
Lets say I have 2 tables:
"tblContactDeta ils" with fields "ContactID" and "UserName" and
"tblCommTra ck" with fields "CommTrackI D", "ContactID" , "CommType", "DateContac ted"
Case one: tblCommTrack has one row with values: 1,10,1, 2008-03-13 respectively. The following query works, because it doesn't return any rows for the indivudual with ContactID=10 WHERE CommType=1 AND DateContacted=2 008-03-13
Expand|Select|Wrap|Line Numbers
  1.  SELECT DISTINCT(d.ContactID), d.UserName FROM tblContactDetails AS d Left Join tblCommTrack AS c ON d.ContactID = c.ContactID WHERE (c.CommTrackID IS NULL OR c.CommType=2 OR (c.DateContacted <> 2008-03-13) ORDER By d.UserName
Case two: tblCommTrack has two rows with values: 1,10,1, 2008-03-13 and 1,10,2, 2008-03-13 Now the query doesn't work, because a record for individual with ContactID=10 is returned, and I don't want that. I only want to return records for individuals who don't have a value of 1 in the CommType field AND if the record with CommType=1 has DateContacted=2 008-03-13.
Mar 13 '08 #1
3 1466
gertie2008
11 New Member
Problem solved:
Expand|Select|Wrap|Line Numbers
  1. CREATE DEFINER=`root`@`localhost` PROCEDURE `getSpecNotContacted`(
  2. IN CoachID INT,
  3. IN iCommType INT,
  4. IN fromDate DATE,
  5. IN toDate DATE
  6. )
  7. BEGIN
  8. drop table IF EXISTS temp;
  9. CREATE TEMPORARY TABLE temp (CommTrackID INT, ContactID INT);
  10.  
  11.    INSERT INTO temp
  12.    SELECT CommTrackID, ContactID FROM tblCommTrack
  13.    WHERE DateContacted >= fromDate
  14.    AND DateContacted <= toDate
  15.    AND CommType=iCommType;
  16.  
  17.  
  18. SELECT DISTINCT(d.ContactID), d.UserName, d.TelCell
  19. FROM tblContactDetails AS d Left Join temp AS t ON d.ContactID = t.ContactID
  20. WHERE t.CommTrackID IS NULL
  21. AND d.CoachedByContactID = CoachID
  22. AND d.ContactID <> CoachID ORDER By d.UserName;
  23. END
Mar 14 '08 #2
ronverdonk
4,258 Recognized Expert Specialist
Congrats on finding the solution.

However, the moderators cannot continue to change your posts for enclosing code within code tags!!

So enclose any code within the proper code tags. See the Posting Guidelines on how to do that.

MODERATOR
Mar 14 '08 #3
gertie2008
11 New Member
Problem solved:
Expand|Select|Wrap|Line Numbers
  1. CREATE DEFINER=`root`@`localhost` PROCEDURE `getSpecNotContacted`(
  2. IN CoachID INT,
  3. IN iCommType INT,
  4. IN fromDate DATE,
  5. IN toDate DATE
  6. )
  7. BEGIN
  8. drop table IF EXISTS temp;
  9. CREATE TEMPORARY TABLE temp (CommTrackID INT, ContactID INT);
  10.  
  11.    INSERT INTO temp
  12.    SELECT CommTrackID, ContactID FROM tblCommTrack
  13.    WHERE DateContacted >= fromDate
  14.    AND DateContacted <= toDate
  15.    AND CommType=iCommType;
  16.  
  17.  
  18. SELECT DISTINCT(d.ContactID), d.UserName, d.TelCell
  19. FROM tblContactDetails AS d Left Join temp AS t ON d.ContactID = t.ContactID
  20. WHERE t.CommTrackID IS NULL
  21. AND d.CoachedByContactID = CoachID
  22. AND d.ContactID <> CoachID ORDER By d.UserName;
  23. END
This is what I came up with. Does anyone know a shorter way? (Thanks ronverdonk for helping me to post better.)
Mar 17 '08 #4

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

Similar topics

3
8707
by: Martin Feuersteiner | last post by:
Dear Group I wonder whether you can give me a syntax example for a SQL Statement. Lets assume I've a table containing three columns ContactID (Primary Key), Firstname and Lastname. I would like to write a stored procedure which returns me the first ten records and increments an outside variable each time it runs. E.g If I run it the first time I pass the variable as 0 and it will return
3
3541
by: Ian T | last post by:
Hi, I've got what I think (probably incorrectly) should be a simple SELECT : Two colums with data like col1 col2 1 50 1 51 2 50
12
6542
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the courses to pass the correct option value and then be displayed at the following URL: http://www.dslextreme.com/users/kevinlyons/selectResults.html I am passing countries, products, and courses. The first two display
3
6459
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I COULD be wrong... :) I've tried the access group...twice...and all I get is "Access doesn't like ".", which I know, or that my query names are too long, as there's a limit to the length of the SQL statement(s). But this works when I don't try to...
6
2268
by: iam247 | last post by:
Hi I am a relative beginner with ASP and weak on syntax for sql statements. Basically I modify something which works. I have tblGroupContact with two fields both long integer - ContactID & GroupID I am using asp3.0 and VB Script
0
1076
by: iam247 | last post by:
Hi I'm using Access 2002. I have 2 tables tblGroupContact, tblGroupPermission, both have 2 fields identical structure: ContactID GroupID (Both are Composite keys and both hold integers) tblGroupContact holds everybody and the groups they are members of. tblGroupPermission holds only those people who have permission to make changes to another part of the DB.
4
3656
by: deepee | last post by:
I have a drop down box in HTML using SELECT and OPTION tags: <select title="Choose a number" onchange="obscure()" name="Digit1" ID="Digit1"> <OPTION VALUE="">&nbsp;</OPTION> <OPTION VALUE="0">&nbsp;0</OPTION> <OPTION VALUE="1">&nbsp;1</OPTION> <OPTION VALUE="2">&nbsp;2</OPTION> <OPTION VALUE="3">&nbsp;3</OPTION> </select>
0
1205
by: mfh | last post by:
Hi, This is my first post. Thanks for all the information provided on the site. I read some posts and I didn't find exactly what I was looking for. I am creating a database to log calls Leaders received from customer service agents. I need to have a ContactID to track each call received. I have about 20+ people using the database shared in the server at the time. I tried to launch the database with the built in Access autonumber and the...
2
1669
by: printline | last post by:
Hi all I have a problem with a form script. The form script should do the following: When a user selects a value from a drop down list and hits the "next" button it should take him to a specific site. Also he has the option to check a checkbox "Remeber this choice" so that when he returns to the site it remembers what he has choosen from the drop down list and automatically takes him to a specific site. Here is my code:
0
8598
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
8531
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
9077
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8951
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8793
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...
1
6457
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
5811
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();...
1
2965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2225
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.