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

Parameters In a Union Query

Hi All,

I'm trying to find the best way to accomplish the following:

I have a union query in an Access XP database (pasted below)

SELECT Contacts.Company,Contacts.dba, Contacts.Misc1, Contacts.Misc2,
Contacts.Address1, Contacts.City, Contacts.State, Contacts.Zip1,
Contacts.top_50, Contacts.B_ID as BID,'BCM' as thesource
FROM Contacts
UNION ALL
SELECT BrokerList.BrokerName AS company,BETdba as dba, BrokerList.BDM
AS misc1, BrokerList.Status AS misc2, BrokerList.Address AS address1,
BrokerList.City, BrokerList.State, BrokerList.Zip AS zip1, False AS
top_50, BrokerList.BrokerID as BID, 'BL' as thesource FROM BrokerList
UNION ALL
SELECT Ineligible.Broker AS Company,'NA' as dba, 'NA' AS Misc1,
Ineligible.Status AS Misc2, Ineligible.Address AS Address1,
Ineligible.City, Ineligible.State, Ineligible.Zip AS Zip1, False AS
top_50, 'NA' AS BID, 'IL' AS the_source
FROM Ineligible

I'm using an ASP page to display the data. Currently I'm using a
parameter after the entire union query has executed - very inefficient

Using ADO what is the best way to pass the parameters to the union
query --
1.) Execute a saved query -- if so, how do I declare the
params in a union query in access. Then I would append params using
the command object? Or could I use execute with the Connection object
and pass the params that way?
2.) Use a sql string with the params declared in the asp
page and execute it dynamically.

The same parameters will be used in each individual query, Do I need to
pass them for each query? Any help would be appreciated

Thanks in Advance
Brian

May 3 '06 #1
1 5792
Hi Brian,

I have used functions inside of union queries. However, I don't know if
this would work from an ASP. But you create a function which returns a
string, int, ... Inside the function you set the value of the function
to a global variable.

Function x() As string
x = globalVar
End Function

You set the value of the global var from a sub that you call from your
client app. This is doable from Excel, another Access app, a vb app.
But I don't know if you can call a sub from an ASP. In the sub you set
the value of the global var.

public globalvar As String

Sub setVal(x as string)
globalvar = x
End Sub

The thing with the function is that a query from the query builder can
have a function in the select statement.

Select ... From tblx where something = x()

Two other alternatives would be 1) use an ADODB command object and set
the select statement in the text of the command object
<%
'--this is off the top of my head - haven't used asp for a while
set cmd = createObject("ADODB.Command") 'I forget the class
cmd.ActiveConnection = filepath(something)
cmd.ActiveConnection.CursorLocation = adUseClient
cmd.CommandType = adCmdText
cmd.CommandText = "Select... Union All select... Union..."
set RS = cmd.Execute
Do While Not RS.EOF
%>
<table>
<tr><td><%RS(0)%><td><%RS(1)%><td>....
</table>

Option 2) populate one table from the tables that make up the union
query, again, using the command object and an insert statement, then use
a command object to select the data from the table you populated

hth

Rich

*** Sent via Developersdex http://www.developersdex.com ***
May 3 '06 #2

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

Similar topics

3
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 ...
2
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 ...
2
by: marco | last post by:
Dear List, as it seems, MS SQL as used in Access does not allow a select INTO within a UNION query. Also, it seems that a UNION query can not be used as a subquery. Maybe my (simplified)...
7
by: serge | last post by:
How can I run a single SP by asking multiple sales question either by using the logical operator AND for all the questions; or using the logical operator OR for all the questions. So it's always...
7
by: KoliPoki | last post by:
Hello every body. I have a small issue. Problem: I have a table with 4 descriptor columns (type). I need to formulate a query to retrieve a count for each type so I can group by...etc. The...
1
by: AJ | last post by:
Folllowing on from a previous post, i have created a stored query as follows. SELECT c.ID, c.Company_Name, p., 1 As QueryNbr FROM (Company AS c LEFT JOIN Sale AS s ON c.ID = s.Company_ID) LEFT...
4
by: arak123 | last post by:
consider the following oversimplified and fictional code public void CreateInvoices(Invoice invoices) { IDbCommand command=Util.CreateDbCommand(); foreach(Invoice invoice in invoices) //lets...
5
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...
27
by: MLH | last post by:
How can I turn the following into a make-table query? SELECT & " " & AS Recipient FROM tblVehicleJobs INNER JOIN tblAddnlOwnrs ON tblVehicleJobs.VehicleJobID = tblAddnlOwnrs.VehicleJobID WHERE...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.