473,785 Members | 2,298 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Selecting variables automatically in GROUP BY query

2 New Member
Hi All:

I'm using Access 2003 on Windows XP.

I'm creating a table where i'll be adding a new variable every week (based on the week number). This is a numeric variable. Once the variable is inserted, i need to run a GROUP BY query based on other character variables. For instance, i'm having a table as:

EMP_ID
Sales_week1
Sales_week2
Sales_week3,

my SQL query will be,
Expand|Select|Wrap|Line Numbers
  1. SELECT EMP_ID, SUM(sales_week1) as week1, SUM(sales_week2) as week2, SUM(sales_week3) as week3
  2. FROM table1
  3. group by EMP_ID;
next week, when i add another variable Sales_week4. The query should update to:
Expand|Select|Wrap|Line Numbers
  1. SELECT EMP_ID, SUM(sales_week1) as week1, SUM(sales_week2) as week2, SUM(sales_week3) as week3, SUM(sales_week4) as week4
  2. FROM table1
  3. group by EMP_ID;
I'm not sure how to automate this in Access.

Any help on this is appreciated.


Regards,
-Deepak
Sep 7 '09 #1
5 4076
beacon
579 Contributor
I'm just curious if there's a reason why you wouldn't include another field in the table for the date at the beginning of the week instead of applying the literal "Week 1" to each week's numbers.

I'm also not sure whether your setup is ideal for what you're trying to do. Is EMP_ID the name of the table? If so, why not call this the SALES_BY_WEEK table? Then your fields would be:

Emp_ID | Sales | Week
0001 $2,000 03/01/2009
0002 $3,000 03/01/2009
0001 $1,000 03/08/2009

Then, if you really wanted to have "Week 1", you could write an expression for a field in your query that recognizes 03/01/2009 as "Week 1" and then increments the number for each subsequent week.

I could be way off from what you are wanting, so forgive me if it's not.
Sep 7 '09 #2
NeoPa
32,578 Recognized Expert Moderator MVP
The difficulty you are experiencing is a good illustration of why the approach you're taking is never advised.

I suggest you consider redesigning the data organisation of you database. Here's a very useful link to help (Normalisation and Table structures).
Sep 7 '09 #3
deepakkumars
2 New Member
To re-structure the table will be a problem as there are more 150,000 records in the table. So, if I add a variable as week and start appending the table, the size of the file will be really huge.

I was thinking if i could create a string using some kind of macros, the string would basically contain the SQL query and somehow run this string as query.

Is it possible??
Sep 8 '09 #4
NeoPa
32,578 Recognized Expert Moderator MVP
** WARNING - This is a very bad idea **

Never say I didn't warn you. Even when things get horribly messy for you down the line.

Having said that, it is possible.

QueryDefs have a .SQL property which can be accessed via VBA code in your database. They can even be updated in the same way (using the .SQL property). A SQL string can be run as a query (a limitation is that only action queries can be run this way) by using :
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL {SQL string value}
For a SELECT query you would need to update the QueryDef before running it.
Sep 8 '09 #5
FishVal
2,653 Recognized Expert Specialist
@deepakkumars
  • Records count doesn't matter.
  • File size will be of the same if not a smaller size.
  • If you could create "some kind of macros", then you certainly could create "some kind of queries" to transfer existing data to a normal table schema.
  • ??????
  • PROFIT!!!
Sep 8 '09 #6

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

Similar topics

1
2617
by: sks | last post by:
Hi, I have a table which logs for sake of argument page hits: id, timestamp, ipaddress Now, I'm running a query to get an activity report and I want to group together all the hits from a certain time period. Let's say a month. I can do this with this query:
3
1360
by: chfran | last post by:
I have a form that is my criteria form. So, if a person enters a State into the State combobox (ex. UT) then everything from that State will appear when the user runs the query (based on the criteria entered into the form). I have 'All' as a category in the same combo box if the user wants to see national information. But, it doesn't like 'All'. So, I've tried "*" (asterisk). It still doesn't like it. So, what type of information...
4
1301
by: Iwan Petrow | last post by:
Hi, Are there any options to set local variables in methods automatically (in Visual Studio 2003)? Example: public void Method(){ int i; //I want i=0 ArrayList a; //I want a=null
2
1501
by: Alex Scollay | last post by:
Let's say I have a column whose values are all 2-digit integers, e.g. 82 (though it's actually a varchar field). From now on, the column will be able to have 2-digit as well as 3-digit integers. In the application that uses these values, a value of the format x0y is considered to be the same as xy. E.g. values 82 and 802 are considered to be the same, 45 and 405 are considered to be the same, etc. Both formats still have to be...
1
17251
by: michael.martinek | last post by:
Greetings! I've recently been trying to do something, which apparently looks like it may be a little odd.. I'm not finding anything in the manuals or anywhere on the web where something similiar is being done.. so it looks like my two options now are to post for some assistance, or find another way to accomplish my task. Basically, what I'm trying to do is select the number of duplicate entries from a table using three columns. There...
19
17993
MSeda
by: MSeda | last post by:
I would like to use a Global variable as a criteria in an access query. in my first attempt to do so I wrote a Function that looks like this Public Function GloVar(ByVal VarName) As String GloVar = VarName End Function It Didn't Work.
6
3735
by: nbomike | last post by:
I am trying to integrate a custom page into a shopping cart app written in PHP. The custom page is basically a part finder widget that helps customers find a car part based on the car's make, model, year, etc. This custom page has a form that submits the page to itself. It does this because I have four drop down menus, and the data in each following drop down is dependent on the previous selection. Since there was so much data, I didn't want to...
4
1249
by: daanoz | last post by:
hey I'm trying to make a query which selects all rows that are not linked to the a certain number, i already managed to do this with a subquery, but this slows down the application, mainly caused because i have more then 100k rows. (simplefied) table ############################ # RowId # MessageId # Type # ############################ # 1 # 104 # 3 #
2
1991
by: JaketheSnake27 | last post by:
I'm trying to define a field in a query using an expression. Part of that expression involves using public variables. First of all, is it possible to use variables in a query field? And if it is, what is the proper syntax for doing so? Example: (This is in the query design. is a current field in the query. EPEI and DC are the variables I want to use to calculate the LTR.) LTR: +"EPEI"+"DC" (Access doesn't recognize EPEI and DC when I...
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10341
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...
0
10155
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10095
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,...
1
7502
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
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4054
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
3656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.