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

How to format fields in UNION query?

8,435 Expert 8TB
Hi all.

First off, this relates to Access 2003.

I have created queries in a couple of databases, in which I have set the Format property for some calculated fields to show hours, minutes and seconds. Now I want to create a separate database to use as the front-end, separate from the data. In this, I have a UNION query which combines the identical tables in various databases.

It works well, but the calculated fields come out as a long decimal number, which is no use. How can I set the format for the calculated fields, in the UNION query? In the other cases I just brought up the properties for the field in the query designer, and set Format appropriately. This doesn't have any visible effect on the SQL, so I don't know what to do now. UNIONs don't allow one to use the designer, only the SQL view.
Oct 22 '06 #1
4 23517
MMcCarthy
14,534 Expert Mod 8TB
SELECT Format(NumberField,"0.00"), Field2, Field3
FROM Table1
UNION
SELECT Format(NumberField,"0.00"), Field2, Field3
FROM Table2
UNION
SELECT Format(NumberField,"0.00"), Field2, Field3
FROM Table3
Oct 22 '06 #2
Killer42
8,435 Expert 8TB
SELECT Format(NumberField,"0.00"), Field2, Field3
FROM Table1
UNION
SELECT Format(NumberField,"0.00"), Field2, Field3
FROM Table2
UNION
SELECT Format(NumberField,"0.00"), Field2, Field3
FROM Table3
Thanks for that, mmccarthy.

What I've done this morning is to create a second query based on the UNION query, and set the Format property for the fields in that. It appears to work.

When I have time, I'll try your method, as I'd prefer not to add yet another level. One of these days I'll have to find time to do a comparison of the performance. Any idea whether there's much difference?

Hm... On further consideration, I'm not sure whether the Format() function will provide what I need in this case. you see, I'm using a format of "hh:nn:ss" to format an amount of time. Unfortunately this clocks over after 24 hours, so I can't really believe what I see there. I tend to copy/paste interesting results into Excel, and reformat there. Since it's a number, this currently works. But if it's a formatted string, it might not. Anyway, I'll let you know how it all works out.

Ta.
Oct 23 '06 #3
jbrink
1
I have the same issue with union all.....This format function in the query works on a single select statement but once you create a union with another table using the same format function the formatting is not implemented... How can you get the formatting to stick on the output?
Jan 18 '08 #4
Killer42
8,435 Expert 8TB
I have the same issue with union all.....This format function in the query works on a single select statement but once you create a union with another table using the same format function the formatting is not implemented... How can you get the formatting to stick on the output?
I can't recall whether Mary's suggestion worked or not. Looking over an old database here, I see that I do have a query which uses my method. That is, the union query comines not tables, but queries which already include the formatting. It does appear to work.

For example..

Table1 includes fields Time1, Time2
Table2 includes fields Time1, Time2

and so on.

Query1 says Select hms([Time2]-[Time1]) AS ElapsedTimed From Table1
Query2 says Select hms([Time2]-[Time1]) AS ElapsedTimed From Table2

etc.

Then the biggy says

SELECT * FROM Query1
UNION ALL
SELECT * FROM Query2

blah blah blah.

Note, the hms() function just returns the passed date/time value in the format I wanted.

This approach does work. But of course the usual rule applies - don't "where out" your functions. :) If you use a WHERE clause on the ElapsedTime field, you'll get (in my case) the three day wait that you deserve. Because Access will have to read all the millions of records and pass their values through the function, to determine which records to read. :(
Jan 21 '08 #5

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

Similar topics

1
by: jj | last post by:
Hi NG I got 2 tables In both of the tables there are 4 indentical fields 1) Road name 2) House number 3) Letter 4) Floor In table one there is an extra field - an Id field. In this table...
2
by: DD | last post by:
I have a UnionQry that is run from StatementsI and StatementP. the Due and Paid colunms are currency and show the $ however when i union the two the currency format has gone. Any help please...
8
by: Bill | last post by:
Hello out there; This may be a challenge but I'm certain it's possible but I can't seem to figure out how. I have a table that has several date fields, e.g., Date1, Date2, Date3, Date4 ......
2
by: Rachel Curran | last post by:
Please can anybody help me with the following: I have two separate excel spreadsheets that I have imported into access, each sheet holds the same fields. Both spreadsheets hold all information...
1
by: Grim Reaper | last post by:
I asked this question, earlier, and received an answer that I am not sure about how to do. Basically, I am printing mailing labels with a "Sorting/Grouping" section that groups the label types...
1
by: Chris Wolfe | last post by:
I have two fields that draw their combobox values from the same table. LogBook04.Insurance is the Primary Insurance and LogBook04.SecIns is the Secondary Insurance. Both draw their values from...
1
by: PATGMorris | last post by:
I've got a Union Query that pulls data from two different tables for chemistry and micro testing. The tables containing very similar data but for reasons not necessary here, cannot be put into one...
2
by: ralamo | last post by:
When i execute the following insert query, the above mentioned error is coming. Anything wrong in the query? INSERT INTO ECN_1 (Old_SbPartNo, Old_PartDesc, Old_ManPartNo, Old_Manuf,...
2
by: carl.barrett | last post by:
Hi, I'm back with the same question as I still can't get it to display my data the way I want it to. The table lists information about a perpetrator involved with an anti social behaviour...
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
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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.