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

Fill query column with my own values

Hello

I have a query that takes information from the column of a table, very
simply:

SELECT NAME
FROM tblPeople;

I want to add another column to my query, but I just want the rows to
contain one value, say 0, and I want to specify that value in the SQL
.... how do I do that? I recall seeing how one does it somewhere...and
without referring to a table with this value...

The point of doing this, is so that I can do a union query, and I need
to make the two participating queries have equal nubers of columns.

Please help!

Nov 13 '05 #1
7 6257
Yes, it is possible. First, don't use a reserved word (i.e. Name) for a
field name. It could cause you problems if you aren't very careful.

SELECT Name, 0 As MyField
FROM tblPeople;

I have done this with UnionQueries to set up a "tag" field so that I could
tell which original query the record came from when looking at the Union
Query.

--
Wayne Morgan
MS Access MVP
"Jean" <je**********@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hello

I have a query that takes information from the column of a table, very
simply:

SELECT NAME
FROM tblPeople;

I want to add another column to my query, but I just want the rows to
contain one value, say 0, and I want to specify that value in the SQL
... how do I do that? I recall seeing how one does it somewhere...and
without referring to a table with this value...

The point of doing this, is so that I can do a union query, and I need
to make the two participating queries have equal nubers of columns.

Please help!

Nov 13 '05 #2
"Jean" <je**********@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hello

I have a query that takes information from the column of a table, very
simply:

SELECT NAME
FROM tblPeople;

I want to add another column to my query, but I just want the rows to
contain one value, say 0, and I want to specify that value in the SQL
... how do I do that?


SELECT NAME, "0" AS MyField
FROM tblPeople;

Regards,
Keith.
www.keithwilby.com
Nov 13 '05 #3
ken
OK...I might be able to answer this!

how about like this:

SELECT tblPeople.NAME, 0 AS MyColumn
FROM tblPeople;

If you want to do this in design view, then in Field cell of the query
type in "MyColumn:0" with out the quotes ofcourse and that will do it
as well. Go to SQL view and you should see something similar to above...

Nov 13 '05 #4
Great stuff, thanks guys!

Your solutions helped me solve my problem. now for Step 2:
I have the union query now, with two columns as follows:

PName Amount
----- ------
AXL 0
LIS 3
BCA 2
BCA 0
THE 1
CHR 0
CHR 5
.... ....

When there are two rows for a PName, e.g. for BCA, I want the next
query (or even better within the union query) to select the PName that
is not null.
I.e. the final result will look like this:

PName Amount
----- ------
AXL 0
LIS 3
BCA 2
THE 1
CHR 5
.... ....

Nov 13 '05 #5
I've tried this so far, the union query as a subquery:

SELECT DISTINCT PNAME, AMOUNT FROM (Select PNAME, AMOUNT FROM
qryByDept UNION Select PNAME, AMOUNT FROM qryBySpecDept);

No luck...yet

Nov 13 '05 #6
Jean wrote:
I've tried this so far, the union query as a subquery:

SELECT DISTINCT PNAME, AMOUNT FROM (Select PNAME, AMOUNT FROM
qryByDept UNION Select PNAME, AMOUNT FROM qryBySpecDept);

No luck...yet


I after reading your post I somehow came up with:

SELECT DISTINCT PName, Nz(IIf((SELECT COUNT([PName]) FROM
tblPName)=1,[PName],(SELECT FIRST(A.Amount) FROM tblPName AS A WHERE
A.Amount <> 0 AND A.PName = tblPName.PName)), 0) AS Amount FROM
tblPName;

It produced:

PName Amount
AXL 0
BCA 2
CHR 5
LIS 3
THE 1

I also saw other ways to do it. I don't know if you care that it
orders the results by PName. The way it works is somewhat inefficient.
For each PName, if that PName is unique in tblPName use its Amount else
use the first non-zero Amount it finds with that PName. Then the
distinct part takes care of the duplicate lines.

James A. Fortune

Nov 13 '05 #7
Hi James,

Thanks for the reply, that just did the trick.

Regards,
Jean

Nov 13 '05 #8

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

Similar topics

5
by: Ken1 | last post by:
I am going to drop a primary key from one column and create a new column to be used as primary key in an existing database. The old column was a date column which someone earlier though was a good...
4
by: Sherwood Botsford | last post by:
Table Markers ID (Primary Key) This&That PointClass (Combo box) Points Table PointClasses PointClass (primary key) Points (number) Description (Text)
5
by: Giz | last post by:
Hi, How can I get a Crosstab Query to fill out a Table like so:- A B C +----+----+---- 1: 1A : 1B : 1C 2: 2A : 2B : 2C 3: 3A : 3B : 3C
1
by: Tom G | last post by:
Hello, I need some advice on which way to resolve the following. On a form, the user will make a selection from a combo box, after the selection several different fields need to be updated on...
4
by: marko | last post by:
Hello. I hope tht someone is going to be able tohelp me, so here is my problem. I have a main table with ID(primary Key),Brend,Model,Price. Then I have a sales table which is filled with a sales...
2
by: Nenad Markovic | last post by:
Hi everybody, When executing a Crosstab Query I see only rows (defined in a row heading) that have values (defined in value field) in at least one column (defined as column headings). How can...
10
by: dauphian | last post by:
Hello, I am new to .net and am trying to build a report application that queries 4 different tables based on a id, and I need to return them in the same table for easy viewing. Basically, I...
1
by: Intrepid_Yellow | last post by:
Hi, I have the following code that runs my report generator. The user selects a table from a combo box, then whatever fields they want from a list box. (This part all works and the report runs...
4
by: khengi | last post by:
Hi, I'm a newbie, so I guess this is a question that expresses my total ignorance, but never the less: I have an old table into which I want to add a column that will automatically update based...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
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...
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,...
0
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...

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.