473,804 Members | 3,305 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Union select with All need to order by number

I have the following SQL statement in code that is set to the RowSource of a
combobox. The combobox has two columns.

SELECT '(ALL)' As Site, '' As [Fac Count], 0 As SortFirst
FROM [BUILDING_TABLE]
GROUP BY SITE_COMPLEX

UNION SELECT SITE_COMPLEX As Site, Count(BLDG_ID) As [Fac Count], 1 As
SortFirst
FROM [BUILDING_TABLE]
WHERE Nz(SITE_COMPLEX ,'') IN
(SELECT SITE FROM [USER_SITE_TABLE] WHERE ALLOWED_TO_VIEW = True And User_ID
= 'John_Doe') GROUP BY SITE_COMPLEX ORDER BY SortFirst, [Fac Count] DESC

I've split it up a bit, hopefully for easier reading. It works but I want
the sorting on Fac Count to be a numerical sort and not a textual sort.
Because I have in the first part of the statement (before the UNION), "" As
[Fac Count], the sorting is textual. If I change it to 0 As [Fac Count], the
sorting is numerical which is what I want. But I don't want 0 to show up
next to (All) in the combobox. I want it to be blank.

I tried

Null As Site - this gave gibberish for the counts in the combobox
Empty As Site - this caused an error.
As Site - this also cause an error

Don't know what else to try.

Thanks for any help.

--
Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200608/1

Aug 26 '06 #1
4 2467
"rdemyan via AccessMonster.c om" <u6836@uwewro te in
news:6553251fbc 7e9@uwe:
I have the following SQL statement in code that is set to the
RowSource of a combobox. The combobox has two columns.

SELECT '(ALL)' As Site, '' As [Fac Count], 0 As SortFirst
FROM [BUILDING_TABLE]
GROUP BY SITE_COMPLEX

UNION SELECT SITE_COMPLEX As Site, Count(BLDG_ID) As [Fac
Count], 1 As SortFirst
FROM [BUILDING_TABLE]
WHERE Nz(SITE_COMPLEX ,'') IN
(SELECT SITE FROM [USER_SITE_TABLE] WHERE ALLOWED_TO_VIEW =
True And User_ID = 'John_Doe') GROUP BY SITE_COMPLEX ORDER BY
SortFirst, [Fac Count] DESC

I've split it up a bit, hopefully for easier reading. It
works but I want the sorting on Fac Count to be a numerical
sort and not a textual sort. Because I have in the first part
of the statement (before the UNION), "" As [Fac Count], the
sorting is textual. If I change it to 0 As [Fac Count], the
sorting is numerical which is what I want. But I don't want 0
to show up next to (All) in the combobox. I want it to be
blank.

I tried

Null As Site - this gave gibberish for the counts in the
combobox Empty As Site - this caused an error.
As Site - this also cause an error

Don't know what else to try.

Thanks for any help.
You need a number as [fac count] in the upper select.

Do you wish to display [fac count] as a column in the listbox?

If you dont, just put 0 as [Fac Count] in the first select
statement.
If you do, you could put a dcount("BLDG_ID ","BUILDING_TAB LE") as
[Fac Count].
--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Aug 26 '06 #2
Thanks for the reply.

I do want to display [fac count] in the combobox, but next to the "(All)"
entry I want it to be spaces. Next to the other sites I want the actual
number.

So the combobox will have entries similar to the following:

(All)
New York 224
Boston 115
Las Vegas 90
Tucson 62
And so on. I have a good reason why I want (All) to not have a record count
next to it, but it's a very long story and is not really germane to my
question. It looks like there might not be a way to do what I want.

Bob Quintal wrote:
>I have the following SQL statement in code that is set to the
RowSource of a combobox. The combobox has two columns.
[quoted text clipped - 29 lines]
>>
Thanks for any help.

You need a number as [fac count] in the upper select.

Do you wish to display [fac count] as a column in the listbox?

If you dont, just put 0 as [Fac Count] in the first select
statement.
If you do, you could put a dcount("BLDG_ID ","BUILDING_TAB LE") as
[Fac Count].
--
Message posted via http://www.accessmonster.com

Aug 26 '06 #3
"rdemyan via AccessMonster.c om" <u6836@uwewro te in
news:655bb9acb1 873@uwe:
Thanks for the reply.

I do want to display [fac count] in the combobox, but next to
the "(All)" entry I want it to be spaces. Next to the other
sites I want the actual number.

So the combobox will have entries similar to the following:

(All)
New York 224
Boston 115
Las Vegas 90
Tucson 62
And so on. I have a good reason why I want (All) to not have
a record count next to it, but it's a very long story and is
not really germane to my question. It looks like there might
not be a way to do what I want.

Bob Quintal wrote:
>>I have the following SQL statement in code that is set to
the RowSource of a combobox. The combobox has two columns.
[quoted text clipped - 29 lines]
>>>
Thanks for any help.

You need a number as [fac count] in the upper select.

Do you wish to display [fac count] as a column in the listbox?

If you dont, just put 0 as [Fac Count] in the first select
statement.
If you do, you could put a dcount("BLDG_ID ","BUILDING_TAB LE")
as [Fac Count].
Don't give up hope yet. Put the count column into the query
twice. In the (all) statement, use the number in one of those
columns, and your " " in the second. Sort on the one with the
number, but make it's column width 0, and display the one with
the space. It will have the numbers left justified, but the sort
order will be correct. If you feel really industrious, you could
even replace the displayable version with an expression that
adds spaces to the left of the string, making it right
justified.

..

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Aug 26 '06 #4
Tried your idea and it appears to have worked. Need to test it some more.

Thanks!

Bob Quintal wrote:
>Thanks for the reply.
[quoted text clipped - 29 lines]
>>>If you do, you could put a dcount("BLDG_ID ","BUILDING_TAB LE")
as [Fac Count].

Don't give up hope yet. Put the count column into the query
twice. In the (all) statement, use the number in one of those
columns, and your " " in the second. Sort on the one with the
number, but make it's column width 0, and display the one with
the space. It will have the numbers left justified, but the sort
order will be correct. If you feel really industrious, you could
even replace the displayable version with an expression that
adds spaces to the left of the string, making it right
justified.

.
--
Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200608/1

Aug 27 '06 #5

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

Similar topics

10
12845
by: KENNY L. CHEN | last post by:
Dear experts, I have two tables in my Oracle 8i database: TEST (COL1,COl2,REC_NO) and TEST1 (COL1,COL2,REC_NO). Both tables are unique-indexed on (COL1,COL2,REC_NO). I think the following SQL commands will return the same result but one of my friends don't think so. He said "QUERY 1" will return 1 unsorted record (ROWNUM < 2 ) first then sort the result (ORDER BY COL1 ASC,
3
11977
by: Blake Caraway | last post by:
All, I've seen several posts regarding using UNION or UNION ALL to mash together two or more resultsets into a single result set, but can't seem to find enough info here to help me answer my particular question. I have a stored procedure that gets the column names in a particular format (i.e. "chassis_id"|"chassis_description"|"modify_date") as well as actual data for a given table (in a quote-separated, pipe-delimited
1
1677
by: Tom Schindl | last post by:
Hi, the following Statement worked on MySQL 4.0 but after upgrading to 4.1.12 on win32 the order is not working any more. Is this a known problem or is our SQL simply not useable on 4.1 or is there a bug in MySQL 4.1. ----------------------------8<---------------------------- ( select
3
10548
by: Dalan | last post by:
From reading Access 97 help text, it seems that to do what I need to do will require a Union Query. As this would be my first, I think I might require a little guidance. I have two tables with 10 fields that have like data (for instance both have an item description field, an item price field, a general notes field, etc.) but with different field names. The tables have approximately 20/40 other fields that are dissimilar and not needed...
1
6177
by: Jeff Blee | last post by:
I hope someone can help me get this graph outputing in proper order. After help from Tom, I got a graph to display output from the previous 12 months and include the average of that output all in the one graph. The output was in the order of the months, but after unioning with the averages SQL code, the order is lost. Below is the full sql code that is the data source for the graph: SELECT (Format(.,"mmm"" '""yy")) AS Month,...
5
1925
by: Alicia | last post by:
Hello everyone based on the data, I created a union query which produces this. SELECT ,,, 0 As ClosedCount FROM UNION SELECT ,, 0 AS OpenedCount, FROM ORDER BY , ;
4
1731
by: Justin Koivisto | last post by:
OK, out of my element here once again... I want a query (or something I can use as a record source for a report) to do the following: * look in 2 tables (one field each) to find all entered values (without duplicates) * count the number of records in both tables that has that value for the field.
4
2942
by: shaun palmer | last post by:
when or Where do you use a union query ? how can I wright sql, tblPopulation,* tblcustomer,* one to one with all the appropriate attributes(field). Your help would be greatly appreciated. Thank you.
4
29769
by: danindublin | last post by:
Been a while since I put a query together but I'm stuck getting my head around something. I want to run a query that using multiple wheres and returns two random examples of each. I can get it to work individually but I have over 200 of these to run and a combined report would be so much easier in case I need to re-run. Any help appreciated! SELECT PRODUCT, CONTRACT, NUMBER FROM (PRODUCT, CONTRACT, NUMBER, RAND() FROM db2) Q (PRODUCT,...
0
9587
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10588
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10324
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9161
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7623
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3827
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.