473,387 Members | 1,512 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,387 software developers and data experts.

Union SQL Need your Honest Opinion

Hi All!
First of I apologize for my previews post needing help on union select and not providing so more explanation, but thank you very much for your opinion and sugestion. I have thought about my problem and try to find a solution. I now have few answres and would like to ask for your expertise on how I handled my sql.

I made an sql code, I used sql specific by creating query > new > design view> close the Show Table > right click> click SQL Specific

I choose this method because I have a great need of it and test my record counting in the future. So please bear with me I when I don’t have any vb or macro included, this is just pure sql, and I have three tables and I joined their workorders using UNION SQL And count them using DCount, here is the tricky part, I'm using the DCount condition to produce specific results and I made a simple query so here's the Code:

SELECT "a) Total Workorder for the whole report" As Field, DCount("[Query2]![Workorder]") As [Total]
FROM [Query2];

UNION SELECT"e) No. of Workorders Completed" As Field, DCount("[Query2]![Overdue]Is Null", "[Query2]", "[Query2]![Member_A]Like 'PPC*' And [Query2]![Compliance] Is Not Null")
OR
DCount("[Query2]![Overdue]Is Null", "[Query2]", "[Query2]![Member_A]Like 'PPC*' And [Query2]![Compliance] Is Not Null And [Query2]![Member_B]Not Like 'PPC*'")
FROM [Query2];

My biggest problem is my sql logic here, I thought its going to be easy breezy, but I’m terribly NOT so here's the Idea. I have a query and it has joint field Workorder, Member_A, Member_B, Overdue and Compliance, but coming from different tables.

tblRecord
----------------------------
Workorder Compliance Overdue
01 1
02 1
03
04 1
05 1 1

tblRec1
------------------
Workorder Member_A
01 PPC
02 SLEX
03 PPC
04 PPC
05 SSD

tbRec2
------------------
Workorder Member_B
01 PPC
02 PPC
03 PPC
04 SLEX
05 PPC

I have 2 problems that must be solved
1. count the workorder in the whole table
2. Count workorders in the table where Meber_A like "PPC*" and Compliant = 1, but If Member_A Like "PPC*" and compliant Is Null
then look in tblRec2 and look in Member_B where not like "PPC*"

for problem no.1 I made the sql code:
SELECT "a) Total Workorder for the whole report" As Field, DCount("[Query2]![Workorder]") As [Total]
FROM [Query2];

for problem no. 2 I wrote the code:
UNION SELECT"e) No.of Workorders Completed" As Field, DCount("[Query2]![Overdue]Is Null", "[Query2]", "[Query2]![Member_A]Like 'PPC*' And [Query2]![Compliance] Is Not Null") OR DCount("[Query2]![Overdue]Is Null", "[Query2]", "[Query2]![Member_A]Like 'PPC*' And
[Query2]![Compliance] Is Not Null And [Query2]![Member_B]Not Like 'PPC*'")
FROM [Query2];

Here’s what my sql logic summary that I made for problem no. 2:
overdue is null and who (Member_A) is like ppc* and compliance = 1
Or
overdue isnull and who (Member_A) is like ppc* and compliance isnull and who (Member_B) is not like ppc*

My problem begins here when I get a –1 for the Total which is not an accurate result. The overdue and compliance field is pretty important in the Total outcome of the whole problem and record counting, but I also want to include who were the members participated, you will see them in my Member_A and Member_B fields.
I hope this explanation is not confusing and if it is, I'm willing to provide more, so what do you guys think? Is my logic here right, If not a very good suggestion or opinion would be very helpful.
Mar 12 '08 #1
2 1467
dima69
181 Expert 100+
Hi All!
First of I apologize for my previews post needing help on union select and not providing so more explanation, but thank you very much for your opinion and sugestion. I have thought about my problem and try to find a solution. I now have few answres and would like to ask for your expertise on how I handled my sql.

I made an sql code, I used sql specific by creating query > new > design view> close the Show Table > right click> click SQL Specific

I choose this method because I have a great need of it and test my record counting in the future. So please bear with me I when I don’t have any vb or macro included, this is just pure sql, and I have three tables and I joined their workorders using UNION SQL And count them using DCount, here is the tricky part, I'm using the DCount condition to produce specific results and I made a simple query so here's the Code:

SELECT "a) Total Workorder for the whole report" As Field, DCount("[Query2]![Workorder]") As [Total]
FROM [Query2];

UNION SELECT"e) No. of Workorders Completed" As Field, DCount("[Query2]![Overdue]Is Null", "[Query2]", "[Query2]![Member_A]Like 'PPC*' And [Query2]![Compliance] Is Not Null")
OR
DCount("[Query2]![Overdue]Is Null", "[Query2]", "[Query2]![Member_A]Like 'PPC*' And [Query2]![Compliance] Is Not Null And [Query2]![Member_B]Not Like 'PPC*'")
FROM [Query2];

My biggest problem is my sql logic here, I thought its going to be easy breezy, but I’m terribly NOT so here's the Idea. I have a query and it has joint field Workorder, Member_A, Member_B, Overdue and Compliance, but coming from different tables.

tblRecord
----------------------------
Workorder Compliance Overdue
01 1
02 1
03
04 1
05 1 1

tblRec1
------------------
Workorder Member_A
01 PPC
02 SLEX
03 PPC
04 PPC
05 SSD

tbRec2
------------------
Workorder Member_B
01 PPC
02 PPC
03 PPC
04 SLEX
05 PPC

I have 2 problems that must be solved
1. count the workorder in the whole table
2. Count workorders in the table where Meber_A like "PPC*" and Compliant = 1, but If Member_A Like "PPC*" and compliant Is Null
then look in tblRec2 and look in Member_B where not like "PPC*"

for problem no.1 I made the sql code:
SELECT "a) Total Workorder for the whole report" As Field, DCount("[Query2]![Workorder]") As [Total]
FROM [Query2];

for problem no. 2 I wrote the code:
UNION SELECT"e) No.of Workorders Completed" As Field, DCount("[Query2]![Overdue]Is Null", "[Query2]", "[Query2]![Member_A]Like 'PPC*' And [Query2]![Compliance] Is Not Null") OR DCount("[Query2]![Overdue]Is Null", "[Query2]", "[Query2]![Member_A]Like 'PPC*' And
[Query2]![Compliance] Is Not Null And [Query2]![Member_B]Not Like 'PPC*'")
FROM [Query2];

Here’s what my sql logic summary that I made for problem no. 2:
overdue is null and who (Member_A) is like ppc* and compliance = 1
Or
overdue isnull and who (Member_A) is like ppc* and compliance isnull and who (Member_B) is not like ppc*

My problem begins here when I get a –1 for the Total which is not an accurate result. The overdue and compliance field is pretty important in the Total outcome of the whole problem and record counting, but I also want to include who were the members participated, you will see them in my Member_A and Member_B fields.
I hope this explanation is not confusing and if it is, I'm willing to provide more, so what do you guys think? Is my logic here right, If not a very good suggestion or opinion would be very helpful.
Without getting too deep into your code, I can tell you that your attemtpt to use DCount in a wrong way. What you need is probably Count in Select ... Group By query.
Mar 12 '08 #2
thanks! dima69 I guess I have to rethink about what I really want DCount to do for my query.
Mar 15 '08 #3

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

Similar topics

1
by: dmb000006 | last post by:
My question is about a UNION query to deal with an (annoying) JOIN over two tables. I am joining over a double column primary key (where the order of the columns can be changed). This is sooo...
73
by: Sean Dolan | last post by:
typedef struct ntt { int type; union { int i; char* s; }; }nt; nt n; n.i = 0;
15
by: laurenq uantrell | last post by:
Wondering if there is a physical or realistic limitation to the number of UNION statements I can create in a query? I have a client with approx 250 tables - the data needs to be kept in seperate...
50
by: Mikhail Teterin | last post by:
Hello! The sample program below is compiled fine by gcc (with -Wall), but rejected by Sun's SUNWspro compiler (version 6 update 2). The point of contention is, whether a value for one of the...
30
by: Yevgen Muntyan | last post by:
Hey, Why is it legal to do union U {unsigned char u; int a;}; union U u; u.a = 1; u.u; I tried to find it in the standard, but I only found that
8
by: irwishlaw | last post by:
After compiling and running the following program #include <stdio.h> #include <string.h> typedef union { int a; char b; float c;
6
by: Bob Altman | last post by:
Hi all, I'm struggling to do something really basic. How do I declare a structure that has a union that maps an array of 3 chars with 3 distinct char variables. In other words, I want the...
18
by: Bryan Parkoff | last post by:
I hate using struct / union with dot between two words. How can I use one word instead of two words because I want the source code look reading clear. three variables are shared inside one...
1
by: Cyprus106 | last post by:
I've got a statement as follows that grabs matching records out two tables: "SELECT * FROM BKRETAIL WHERE BKRETAIL.MATK='THISTHE' UNION SELECT * FROM BKMASTER WHERE BKMASTER.MATK='THISTHE'; My...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.