473,805 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Union Query Help - Return TRUE

I have the following union query that works great, but I want to alter
the query to only return True (-1) for the TEST column.

Currently the test column DOES return 0 or -1. I just want the -1.

How can I place logic in this without creating another query.

Here is the union:

SELECT AgencyCode as ContactTypeID, AgencyShortName as ContactName,
Right(RegionNam e,1) as Region, "Agency" as ContactType,
ChkAgyDIS("Agys ",IIf([Forms]![frmMonthlyRepor ts]![txtReportType]="Agys",[contactTypeID]))
as TEST FROM dbo_V_EP_AllAge nciesForAppActi vity UNION ALL
SELECT DISTINCT DISCODE as ContactTypeID, LName & ", " & FName as
ContactName, Right(RegionNam e,1) as Region, "DIS" as ContactType,
ChkAgyDIS("Agys ",IIf([Forms]![frmMonthlyRepor ts]![txtReportType]="Agys",[contactTypeID]))
as TEST FROM qryDISContactsW ithRegionInfo UNION ALL SELECT DISTINCT
EnterpriseParty RoleDescription as ContactTypeID, LName & ", " & FName
as ContactName, IIF(LNAME=Perso n 1,"1",IIF(Instr (LNAME,'Person
2')>0,"2",IIF(I nstr(LNAME,'Per son 3')>0,"3",IIF(I nstr(LNAME,'Per son
4')>0,"4","UNKN OWN")))) as Region, "Region" as ContactType,
ChkAgyDIS("Agys ",IIf([Forms]![frmMonthlyRepor ts]![txtReportType]="Agys",[contactTypeID]))
as TEST FROM dbo_V_EP_GAEmai lContactsForApp Activity WHERE
EnterpriseParty RoleValue ='RSM';

TIA
-Brian

Sep 28 '06 #1
2 2271

BerkshireGuy wrote:
I have the following union query that works great, but I want to alter
the query to only return True (-1) for the TEST column.

Currently the test column DOES return 0 or -1. I just want the -1.

How can I place logic in this without creating another query.

Here is the union:

SELECT AgencyCode as ContactTypeID, AgencyShortName as ContactName,
Right(RegionNam e,1) as Region, "Agency" as ContactType,
ChkAgyDIS("Agys ",IIf([Forms]![frmMonthlyRepor ts]![txtReportType]="Agys",[contactTypeID]))
as TEST FROM dbo_V_EP_AllAge nciesForAppActi vity UNION ALL
SELECT DISTINCT DISCODE as ContactTypeID, LName & ", " & FName as
ContactName, Right(RegionNam e,1) as Region, "DIS" as ContactType,
ChkAgyDIS("Agys ",IIf([Forms]![frmMonthlyRepor ts]![txtReportType]="Agys",[contactTypeID]))
as TEST FROM qryDISContactsW ithRegionInfo UNION ALL SELECT DISTINCT
EnterpriseParty RoleDescription as ContactTypeID, LName & ", " & FName
as ContactName, IIF(LNAME=Perso n 1,"1",IIF(Instr (LNAME,'Person
2')>0,"2",IIF(I nstr(LNAME,'Per son 3')>0,"3",IIF(I nstr(LNAME,'Per son
4')>0,"4","UNKN OWN")))) as Region, "Region" as ContactType,
ChkAgyDIS("Agys ",IIf([Forms]![frmMonthlyRepor ts]![txtReportType]="Agys",[contactTypeID]))
as TEST FROM dbo_V_EP_GAEmai lContactsForApp Activity WHERE
EnterpriseParty RoleValue ='RSM';
Where's the TEST=0 in your filter? If the value is called different
names in different tables, you have to alias them so they all have the
same name.

Sep 28 '06 #2
"BerkshireG uy" <bd*****@yahoo. comwrote in
news:11******** *************@d 34g2000cwd.goog legroups.com:
I have the following union query that works great, but I want
to alter the query to only return True (-1) for the TEST
column.

Currently the test column DOES return 0 or -1. I just want
the -1.

How can I place logic in this without creating another query.

Firstly you need to properly format your query, it's a dog's
breakfast. Break after keywords, after each field definition and
elsewhere as required.
SELECT
AgencyCode as ContactTypeID,
AgencyShortName as ContactName,
Right(RegionNam e,1) as Region,
"Agency" as ContactType,
ChkAgyDIS("Agys ",
IIf([Forms]![frmMonthlyRepor ts]![txtReportType]="Agys",
[contactTypeID])) as TEST
FROM
dbo_V_EP_AllAge nciesForAppActi vity

UNION ALL
SELECT DISTINCT
DISCODE as ContactTypeID,
LName & ", " & FName as ContactName,
Right(RegionNam e,1) as Region,
"DIS" as ContactType,
ChkAgyDIS("Agys ",
IIf([Forms]![frmMonthlyRepor ts]![txtReportType]="Agys",
[contactTypeID])) as TEST
FROM
qryDISContactsW ithRegionInfo

UNION ALL
SELECT DISTINCT
EnterpriseParty RoleDescription as ContactTypeID,
LName & ", " & FName
as ContactName,
IIF(LNAME=Perso n 1,"1",
IIF(Instr(LNAME ,'Person 2')>0,"2",
IIF(Instr(LNAME ,'Person 3')>0,"3",
IIF(Instr(LNAME ,'Person4')>0," 4",
"UNKNOWN")) )) as Region,
"Region" as ContactType,
ChkAgyDIS("Agys ",
IIf([Forms]![frmMonthlyRepor ts]![txtReportType]="Agys",
[contactTypeID])) as TEST
FROM
dbo_V_EP_GAEmai lContactsForApp Activity
WHERE
EnterpriseParty RoleValue ='RSM';

Then you need to insert a "WHERE clause individually in each of
the three queries, that limits the data to the true case of the
expression "test", after the "FROM" keyword and expression
FROM
dbo_V_EP_AllAge nciesForAppActi vity..
WHERE
IIf([Forms]![frmMonthlyRepor ts]![txtReportType]="Agys",
[contactTypeID])) = -1

is the first

the third already has a WHERE clause so you need to put an AND
to join the conditions
WHERE
EnterpriseParty RoleValue ='RSM';
AND
IIf([Forms]![frmMonthlyRepor ts]![txtReportType]="Agys",
[contactTypeID])) = -1

Your homework is to do the second WHERE Clause..

You also are missing quotes around 'person 1' in
IIF(LNAME=Perso n 1,"1",


Bob Q
Here is the union:

SELECT AgencyCode as ContactTypeID, AgencyShortName as
ContactName, Right(RegionNam e,1) as Region, "Agency" as
ContactType,
ChkAgyDIS("Agys ",IIf([Forms]![frmMonthlyRepor ts]!
[txtReportType
]="Agys",[contactTypeID]))
as TEST FROM dbo_V_EP_AllAge nciesForAppActi vity UNION ALL
SELECT DISTINCT DISCODE as ContactTypeID, LName & ", " & FName
as ContactName, Right(RegionNam e,1) as Region, "DIS" as
ContactType,
ChkAgyDIS("Agys ",IIf([Forms]![frmMonthlyRepor ts]!
[txtReportType
]="Agys",[contactTypeID]))
as TEST FROM qryDISContactsW ithRegionInfo UNION ALL SELECT
DISTINCT
EnterpriseParty RoleDescription as ContactTypeID, LName & ", "
& FName as ContactName, IIF(LNAME=Perso n
1,"1",IIF(Instr (LNAME,'Person
2')>0,"2",IIF(I nstr(LNAME,'Per son
3')>0,"3",IIF(I nstr(LNAME,'Per son 4')>0,"4","UNKN OWN")))) as
Region, "Region" as ContactType,
ChkAgyDIS("Agys ",IIf([Forms]![frmMonthlyRepor ts]!
[txtReportType
]="Agys",[contactTypeID]))
as TEST FROM dbo_V_EP_GAEmai lContactsForApp Activity WHERE
EnterpriseParty RoleValue ='RSM';

TIA
-Brian



--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Sep 28 '06 #3

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

Similar topics

10
12846
by: KENNY L. CHEN | last post by:
Dear experts, I have two tables in my Oracle 8i database: TEST (COL1,COl2,REC_NO) and TEST1 (COL1,COL2,REC_NO). Both tables are unique-indexed on (COL1,COL2,REC_NO). I think the following SQL commands will return the same result but one of my friends don't think so. He said "QUERY 1" will return 1 unsorted record (ROWNUM < 2 ) first then sort the result (ORDER BY COL1 ASC,
3
3577
by: Paradigm | last post by:
I am using Access 2K as a front end to a MYSQL database. I am trying to run a Union query on the MYSQL database. The query is (much simplified) SELECT as ID from faxdata UNION SELECT as ID from letdata UNION SELECT as ID FROM MEMODATA; I get an ODBC error. The same query runs when the backend files are MDB files and it runs with MYSQL if I only combine 2 tables.
14
1812
by: Salad | last post by:
A97. Situation: I have 3 tables with a text field in each and a date field in the first 2 tables: Table1 Text1, Date1 Table2 Text2, Date2 Table3 Text3 (no date field) The following makes up a saved query called Query1
2
4346
by: mattytee123 | last post by:
I have about 20 tables, of which I would like to do a union query and count of how many of each different code there is? The simplified verson of the table is structured like this. Code Count 1234 1 2468 1 1234 1 2468 1
9
2937
by: Jeremy | last post by:
I have a situation where i am trying to run two query's and retrieve one record from each query, then using Union combine them into one recordset. The First Query is strait forward and should just return the matching record however the second query needs to find a random record and return it. The union is causing me some trouble. It seems that any method i try to find a random record just causes an error. Here is an example of a query...
1
403
by: BerkshireGuy | last post by:
I have the following union query that runs great. I want to be able to return the returns where the TEST field is True (-1) How do I add criteria to do this without using another query? SELECT AgencyCode as ContactTypeID, AgencyShortName as ContactName, Right(RegionName,1) as Region, "Agency" as ContactType, ChkAgyDIS("Agys",IIf(!!="Agys",)) as TEST FROM dbo_V_EP_AllAgenciesForAppActivity UNION ALL SELECT DISTINCT DISCODE as...
4
11656
by: janko.klemensek | last post by:
Can I Group by the Union in one query or must I write two queries for this (one for union and second for group by)?
5
3850
by: wugon.net | last post by:
question: db2 LUW V8 UNION ALL with table function month() have bad query performance Env: db2 LUW V8 + FP14 Problem : We have history data from 2005/01/01 ~ 2007/05/xx in single big table, we try separate this big table into twelve tables and create a view
2
1720
by: MLH | last post by:
I have a saved UNION query named qryAuthsOwnersAddnlOwnersLienholders4OneCar. Here it is... SELECT & " " & & " " & & " " & & ", " & & " " & & " " & "(" & & " county) " & Format$(,"(@@@) @@@-@@@@") & " " & IIf(=True,"(corporation)","(person)") AS Item, tblVehicleJobs.VehicleJobID, "X" AS OLAX, tblAddnlOwnrs.AddnlOwnrID AS
0
9718
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
10363
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
10107
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
9186
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...
0
6876
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
5544
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
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4327
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
3
3008
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.