473,404 Members | 2,137 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,404 software developers and data experts.

Combine of 2 queries from different Tabled

Hi all.

I have a system which operates on Windows MSSQL.
It is used for registering Suppotr requests. The system works with different Tables inside a Database.

One of the tables is for new support calls , another table is for additions to a support call , call_no being the linked cell.

I'm using Excell to pull the information from MSSQL with queries.

First query for the logged support calls by user :
Expand|Select|Wrap|Line Numbers
  1. SELECT LOGGED_CALLS.LOGGED_BY, CALL_CATEGORIES.DESCRIPTION, LOGGED_CALLS.DATE_LOGGED, LOGGED_CALLS.CALL_NO, LOGGED_CALLS.CALL_DESCRIPTION, LOGGED_CALLS.CALL_DURATION
  2. FROM iesm_support.dbo.CALL_CATEGORIES CALL_CATEGORIES, iesm_support.dbo.LOGGED_CALLS LOGGED_CALLS
  3. WHERE CALL_CATEGORIES.CALL_CATEGORY = LOGGED_CALLS.CALL_CATEGORY AND ((LOGGED_CALLS.LOGGED_BY=64) AND (LOGGED_CALLS.DATE_LOGGED>=? And LOGGED_CALLS.DATE_LOGGED<=?))
  4. ORDER BY LOGGED_CALLS.DATE_LOGGED
Second query for the addtional support call by user :
Expand|Select|Wrap|Line Numbers
  1. SELECT ADDITIONAL_CALLS.LOGGED_BY, CALL_CATEGORIES.DESCRIPTION, ADDITIONAL_CALLS.CALL_NO, ADDITIONAL_CALLS.DATE_LOGGED, ADDITIONAL_CALLS.CALL_DURATION, LOGGED_CALLS.CALL_DESCRIPTION
  2. FROM iesm_support.dbo.ADDITIONAL_CALLS ADDITIONAL_CALLS, iesm_support.dbo.CALL_CATEGORIES CALL_CATEGORIES, iesm_support.dbo.LOGGED_CALLS LOGGED_CALLS
  3. WHERE LOGGED_CALLS.CALL_NO = ADDITIONAL_CALLS.CALL_NO AND LOGGED_CALLS.CALL_CATEGORY = CALL_CATEGORIES.CALL_CATEGORY AND ((ADDITIONAL_CALLS.LOGGED_BY=64) AND (ADDITIONAL_CALLS.DATE_LOGGED>? And ADDITIONAL_CALLS.DATE_LOGGED<?))
What I now have is : Query 1 and Query 2 on different Worksheets in Excel.
What I want : Information from both queries on SAME worksheet in Excel.

Is this even possible ? (I was messing around with UNION but couldn't get it working)

And If it is possible , how to do so ?

Your help is much appriciated , as I'm not an SQL tech , just a support tech ;)

Peter
Mar 31 '07 #1
6 3081
iburyak
1,017 Expert 512MB
I am not an Excel programmer but I am familiar with basic SQL rules.

First I changed position of columns to match them in both queries which is important.

Second I put order by at the end.


Try this:

[PHP]SELECT LOGGED_CALLS.LOGGED_BY, CALL_CATEGORIES.DESCRIPTION, LOGGED_CALLS.CALL_NO,
LOGGED_CALLS.DATE_LOGGED, LOGGED_CALLS.CALL_DURATION, LOGGED_CALLS.CALL_DESCRIPTION,
FROM iesm_support.dbo.CALL_CATEGORIES CALL_CATEGORIES,
iesm_support.dbo.LOGGED_CALLS LOGGED_CALLS
WHERE CALL_CATEGORIES.CALL_CATEGORY = LOGGED_CALLS.CALL_CATEGORY
AND ((LOGGED_CALLS.LOGGED_BY=64)
AND (LOGGED_CALLS.DATE_LOGGED>=? And LOGGED_CALLS.DATE_LOGGED<=?))

UNION

SELECT ADDITIONAL_CALLS.LOGGED_BY, CALL_CATEGORIES.DESCRIPTION, ADDITIONAL_CALLS.CALL_NO,
ADDITIONAL_CALLS.DATE_LOGGED, ADDITIONAL_CALLS.CALL_DURATION, LOGGED_CALLS.CALL_DESCRIPTION
FROM iesm_support.dbo.ADDITIONAL_CALLS ADDITIONAL_CALLS,
iesm_support.dbo.CALL_CATEGORIES CALL_CATEGORIES,
iesm_support.dbo.LOGGED_CALLS LOGGED_CALLS
WHERE LOGGED_CALLS.CALL_NO = ADDITIONAL_CALLS.CALL_NO
AND LOGGED_CALLS.CALL_CATEGORY = CALL_CATEGORIES.CALL_CATEGORY
AND ((ADDITIONAL_CALLS.LOGGED_BY=64)
AND (ADDITIONAL_CALLS.DATE_LOGGED>? And ADDITIONAL_CALLS.DATE_LOGGED<?))
ORDER BY 4[/PHP]

Hope it helps.

Good Luck.
Apr 1 '07 #2
Tnx for helping.

The first step seems logical to me so i've rewritten the Excel queries, both same ordering now.

But when trying your code it displays :
[]
Microsoft Query

Parameters are not allowed in queries that can't be displayed graphically

<OK>
[]

While I was trying to get it going , I also got this error everytime I changed the query.

Peter
Apr 1 '07 #3
iburyak
1,017 Expert 512MB
It is comming from these lines:


[PHP]AND (LOGGED_CALLS.DATE_LOGGED>=? And LOGGED_CALLS.DATE_LOGGED<=?))
AND (ADDITIONAL_CALLS.DATE_LOGGED>? And ADDITIONAL_CALLS.DATE_LOGGED<?))
ORDER BY 4 [/PHP]


Remove thhem and try again.
Apr 1 '07 #4
Tnx but again no go.

When I copy the PHP Code from the Code Block it has a very weird layout (too much spaces and returns ..)

I will dig further , as I cannot get a simple Query from both Tables to display all the wanted information. (I.e in my two excel sheets I get in total 20 results , while the simple query return only 16 results)

Peter
Apr 1 '07 #5
iburyak
1,017 Expert 512MB
Try this:

SELECT LOGGED_CALLS.LOGGED_BY, CALL_CATEGORIES.DESCRIPTION, LOGGED_CALLS.CALL_NO,
LOGGED_CALLS.DATE_LOGGED, LOGGED_CALLS.CALL_DURATION, LOGGED_CALLS.CALL_DESCRIPTION,
FROM iesm_support.dbo.CALL_CATEGORIES CALL_CATEGORIES,
iesm_support.dbo.LOGGED_CALLS LOGGED_CALLS
WHERE CALL_CATEGORIES.CALL_CATEGORY = LOGGED_CALLS.CALL_CATEGORY
AND ((LOGGED_CALLS.LOGGED_BY=64)


UNION All

SELECT ADDITIONAL_CALLS.LOGGED_BY, CALL_CATEGORIES.DESCRIPTION, ADDITIONAL_CALLS.CALL_NO,
ADDITIONAL_CALLS.DATE_LOGGED, ADDITIONAL_CALLS.CALL_DURATION, LOGGED_CALLS.CALL_DESCRIPTION
FROM iesm_support.dbo.ADDITIONAL_CALLS ADDITIONAL_CALLS,
iesm_support.dbo.CALL_CATEGORIES CALL_CATEGORIES,
iesm_support.dbo.LOGGED_CALLS LOGGED_CALLS
WHERE LOGGED_CALLS.CALL_NO = ADDITIONAL_CALLS.CALL_NO
AND LOGGED_CALLS.CALL_CATEGORY = CALL_CATEGORIES.CALL_CATEGORY
AND ((ADDITIONAL_CALLS.LOGGED_BY=64)

ORDER BY 4
Apr 1 '07 #6
Thanks all for helping.

But the company who made the program have included some reports now into the application.

With one of the reports I can see a users activity. With another report I can see the total activity , by day , week or even month

You're help is/was much appriciated !!

Pete
Apr 4 '07 #7

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

Similar topics

9
by: Steve Jorgensen | last post by:
Hi all, I'm working on the schema for a database that must represent data about stock & bond funds over time. My connundrum is that, for any of several dimension fields, including the fund name...
5
by: Jamie Pittman via AccessMonster.com | last post by:
I have two tables with 5000 entries on them. One is based for regular time with several variables example (employee name, date,time in and out, code, customer, building) I have another table that...
2
by: Reidar Jorgensen | last post by:
I have several Access databases, identical in structure, but different data. Is there an easy way to combine them all into one database? There are six tables, I just want the data from all...
4
by: Jason Gyetko | last post by:
Is there any way to combine these two queries into one? I have tables Item_Master & Kit_Master which are the source tables. Query 2 is using both Item_Master (table) & qryKit1 (query) &...
1
by: MackTheKnife | last post by:
I have the following 3 SQL statements that need to be combined, if possible. The output of one feeds the input of the next. I need to view all of the defined output fields (the output needs to be...
1
by: Will | last post by:
Hi all I have a table, where there's AutoID, Name of Person (looked up from tblPerson), Name of Dispute (looked up from tblDispute), Date, Details (Memo). What I have is another table that need...
4
by: PlayHard | last post by:
I want my output in two columns like this: C_INCIDENT_TYPE \ TOTAL COUNT How do I combine my two queries to get result. First Query SELECT C_INCIDENT_TYPE, COUNT (*)
4
by: | last post by:
I have query1 where I set a date range. Query2 is a crosstab query and is based on query1. I don't want the queries to be saved in the mdb but I do want them to be run in VBA using a querystring. If...
1
by: csolomon | last post by:
Hello: I am using two queries to get one result set. The issue is, I return no data when I combine them into one query. I have listed both queries, as well as the 3rd query that shows them...
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
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,...
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
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...
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.