Add "ALL" in combobox, with counting of total records

Luthius

Active Member
Joined
Apr 5, 2011
Messages
324
Well I have the SQL statement below and I want to add the word "ALL" on top, counting all records and Keeping EmployeeID to LastName and "*" for "ALL".

How can I do that?

Code:
SELECT LastName, Count(Orders.EmployeeID) AS ContarDeEmployeeID
FROM Employees INNER JOIN Orders ON Employees.EmployeeID = Orders.EmployeeID
GROUP BY Employees.LastName;

Luthius
 
Last edited:

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Code:
SELECT '<All>' As ContarDeEmployeeID FROM Employees
UNION
SELECT LastName, Count(Orders.EmployeeID) AS ContarDeEmployeeID
FROM Employees INNER JOIN Orders ON Employees.EmployeeID = Orders.EmployeeID
GROUP BY Employees.LastName;

Then in your After Update event of the combobox you'll need to trap for the <All> so you can show all the records.

hth,

Rich
 
Upvote 0
It's not working

The query gives an error:
"The number of columns in the two selected tables or queries of a union query do not match"

I tried to change SELECT '' to put SELECT "*", and nothing... just error.

It's not working

I'm using Northwind database to get there
 
Upvote 0
the union isn't working becuase in a union both queries have to have the same number of and same type of columns

Well I have the SQL statement below and I want to add the word "ALL" on top, counting all records and Keeping EmployeeID to LastName and "*" for "ALL"'.
I don't understand what you're asking
but I think you're asking this
Code:
SELECT 
  LastName, 
  count(*)
FROM 
  your_table_name 

where 
  iif 
  (  
    [param] = 'All',
    1 = 1, 
    Orders.EmployeeID is not null
  )

group 
   by LastName
does that make sense ?
 
Last edited:
Upvote 0
Check it out:

Code:
SELECT Employees.LastName, Count(Orders.EmployeeID) AS [Total of Sales]
FROM Employees INNER JOIN Orders ON Employees.EmployeeID = Orders.EmployeeID
GROUP BY Employees.LastName;

Results:

Last Name Total of Sales
Buchanan 42
Callahan 104
Davolio 123
Dodsworth 43
Fuller 96
King 72
Leverling 127
Peacock 156
Suyama 67

What I want is:



Last Name Total of sales Employee ID
ALL 830 *
Buchanan 42 5
Callahan 104 8
Davolio 123 1
Dodsworth 43 9
Fuller 96 2
King 72 7
Leverling 127 3
Peacock 156 4
Suyama 67 6
 
Upvote 0
I fixed table to show the result as I wish


HTML:
Last Name	       Total of sales	Employee ID
ALL            	        830           	*
Buchanan                42              5
Callahan     	       104              8
Davolio       	       123              1
Dodsworth          	43            	9
Fuller                 	96          	2
King                  	72        	7
Leverling             	127       	3
Peacock             	156     	4
Suyama              	67        	6

I'm using Northwind database.
 
Upvote 0
maybe this ?
but it puts null instead of *
Code:
SELECT 
  Orders.EmployeeID as [Employee ID], 
  LastName as [Last Name], 
  Count(Orders.EmployeeID) AS [Total of Sales]
FROM 
  Employees 
    INNER JOIN 
  Orders 
    ON 
      Employees.EmployeeID = Orders.EmployeeID
GROUP BY 
  Orders.EmployeeID, 
  Employees.LastName 

union all 

select 
  null as [Employee ID], 
  "All" as [Last Name], 
  Count(Orders.EmployeeID) AS [Total of Sales]  
FROM 
  Employees 
    INNER JOIN 
  Orders 
    ON 
      Employees.EmployeeID = Orders.EmployeeID
 
Upvote 0

Forum statistics

Threads
1,224,598
Messages
6,179,814
Members
452,945
Latest member
Bib195

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top