473,795 Members | 3,024 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Select Distinct Problem

I'm using a Visual Basic front end with an SQL query to select some
data from a MS Access database. I have a table named Tithes with
Columns of

TitheDate
Tither No
Total
Tithes
Faith Promise
Building Fund

I have the following query that returns the sum of each column grouped
by year.

SELECT DISTINCTROW Format$([Tithes].[TitheDate],'yyyy') AS [Year],
Sum(Tithes.Tota l) AS Total, Sum(Tithes.Tith es) AS Tithes,
Sum(Tithes.[Faith Promise]) AS [Faith Promise], Sum(Tithes.[Building
Fund]) AS [Building Fund]
FROM Tithes
GROUP BY Format$([Tithes].[TitheDate],'yyyy'),
Year([Tithes].[TitheDate]);

There will be times when I have to add columns to the Tithes table. How
do I update the query to include the added columns?

Sep 20 '06 #1
2 2129
jo*******@gmail .com wrote:
I'm using a Visual Basic front end with an SQL query to select some
data from a MS Access database. I have a table named Tithes with
Columns of

TitheDate
Tither No
Total
Tithes
Faith Promise
Building Fund

I have the following query that returns the sum of each column grouped
by year.

SELECT DISTINCTROW Format$([Tithes].[TitheDate],'yyyy') AS [Year],
Sum(Tithes.Tota l) AS Total, Sum(Tithes.Tith es) AS Tithes,
Sum(Tithes.[Faith Promise]) AS [Faith Promise], Sum(Tithes.[Building
Fund]) AS [Building Fund]
FROM Tithes
GROUP BY Format$([Tithes].[TitheDate],'yyyy'),
Year([Tithes].[TitheDate]);

There will be times when I have to add columns to the Tithes table. How
do I update the query to include the added columns?
Looks like your first problem is an incorrect table design. You should
not have to change the structure of your database over time unless you
start adding new kinds of information.

Could you not use a structure like:

tblTithe(
TitheID,
TitheDate,
Tither_No,
Amount,
Fund)

New Tithers would go in a table (FirstName, LastName...)
Getting how much each person tithed to each account - just use a
summary query.

Group by Tither_no, Fund, Year(TitheDate)

If you want the total amount tithed per year, you just do a totals
query on the Tithe table, sum(Amount). IF you want it by week,
calculate the weekNumber and group by that... This structure should
prove a lot more flexible over time. And easier to query... no PITA
unions and all that nonsense.

Sep 20 '06 #2
If there are times when you need to add tables to your Tithes table
then you don't have your data designed correctly. It sounds like
"Excel Think" but doesn't look like it. What are the occasional
"added columns"? If you ever need to add columns then you always need
to leave them there.

In a relational database, entities in the application are entered into
tables. The tables are designed to conform to at least 3rd Normal
form. If that sounds like gobbledegook I understand. But, it's true.

In your Tithes table what do the fields below Tither No hold? If
total is the sum of the fields below it, get rid of it. One of the
relational rules is that nothing in any field in a record depends or
is derived from any other part of the record.

Just modify your query to include the other columns when needed,
otherwise leave them out.

Otherwise this sounds like a VB issue of where and how to store
queries, not Access. In Access you can embed your queries in the
Forms and Reports that use them or create named Queries and save them
as objects in the database. or write SQL fragments in code and
concatenate them into a string and execute that string as a SQL
statement.

HTH
--
-Larry-
--

<jo*******@gmai l.comwrote in message
news:11******** **************@ d34g2000cwd.goo glegroups.com.. .
I'm using a Visual Basic front end with an SQL query to select some
data from a MS Access database. I have a table named Tithes with
Columns of

TitheDate
Tither No
Total
Tithes
Faith Promise
Building Fund

I have the following query that returns the sum of each column
grouped
by year.

SELECT DISTINCTROW Format$([Tithes].[TitheDate],'yyyy') AS [Year],
Sum(Tithes.Tota l) AS Total, Sum(Tithes.Tith es) AS Tithes,
Sum(Tithes.[Faith Promise]) AS [Faith Promise], Sum(Tithes.[Building
Fund]) AS [Building Fund]
FROM Tithes
GROUP BY Format$([Tithes].[TitheDate],'yyyy'),
Year([Tithes].[TitheDate]);

There will be times when I have to add columns to the Tithes table.
How
do I update the query to include the added columns?

Sep 20 '06 #3

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

Similar topics

5
3669
by: Colman | last post by:
Howdy all! I guess I'm a newbie, because I am stumped (or maybe just too durned tired). Here's what I got... CREATE TABLE `nodecat_map` ( `nodecat_id` mediumint(8) unsigned NOT NULL auto_increment, `nodecat_cat_id` mediumint(8) unsigned NOT NULL default '0', `nodecat_node_id` mediumint(8) unsigned NOT NULL default '0', PRIMARY KEY (`nodecat_id`),
5
11692
by: Martin Feuersteiner | last post by:
Dear Group I'm having trouble with the clause below. I would like to select only records with a distinct TransactionDate but somehow it still lists duplicates. I need to select the TransactionDate once as smalldatetime and once as varchar as I'm populating a drop-down with Text/Value pairs. So I can't just use 'SELECT DISTINCT TransactionDate FROM...' I'm grateful for any hints.
3
6473
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I COULD be wrong... :) I've tried the access group...twice...and all I get is "Access doesn't like ".", which I know, or that my query names are too long, as there's a limit to the length of the SQL statement(s). But this works when I don't try to...
9
10913
by: Kelvin | last post by:
Okay so this is baking my noodle. I want to select all the attritbutes/fields from a table but then to excluded any row in which a single attributes data has been duplicated. I.E. Here's my table:- ID Ref Name DATE 1 AAA Joe 1/2 2 BBB Ken 1/2 3 AAA Len 6/3
6
5560
by: John M | last post by:
Hi, The line below is used to feed a combobox. (It is from a database which is used to log pupil behaviour!) The 'incidents' table contains a list of students who have been involved in incidents. Some may appear several times, hence the Distinct. However, thelist generated should still be sorted by Surname. When I add Order by I'm told it conflict with the 'Distinct'. Surely it does not? SELECT DISTINCT ., . & " " & . FROM...
18
3067
by: mathilda | last post by:
My boss has been adamant that SELECT DISTINCT is a faster query than SELECT all other factors being equal. I disagree. We are linking an Access front end to a SQL Server back end and normally are only returning one record. She states that with disctinct the query stops as soon as it finds a matching record. Both of us are relative novices in database theory (obviously). Can someone help settle this?
2
1470
by: ray well | last post by:
i have to extract info from a legacy access database, which i can't alter, or run APPEND or UPDATE quries against. i can only use SELECT statments to extract what i need. the database has multiple entries for the same first and last name, i need to generate a dataset that has no duplicate first and last names. the sql statment itself is quite easy SELECT DISTINCT tblNameAndAddress.LastName, tblNameAndAddress.FirstName
6
13766
by: Bob Stearns | last post by:
I am getting duplicate rows back from a select distinct statement of the form: SELECT DISTINCT 'jhough', '000111', t0.bhid FROM (SELECT lots of good stuff) t0 LEFT OUTER JOIN another_table t1 ON relevant_stuff WHERE (lots of conditions) After re-reading the relevant pat ofVol 1 of the SQL Reference I am unablee to see how this is possible.
6
13579
by: Bob Stearns | last post by:
I am getting unwanted duplicate rows in my result set, so I added the DISTINCT keyword to my outermost SELECT. My working query then returned the following message: DB2 SQL error: SQLCODE: -214, SQLSTATE: 42822, SQLERRMC: CASE...;ORDER BY;2 Message: An expression in the ORDER BY clause in the following position, or starting with "CASE..." in the "ORDER BY" clause is not valid. Reason code = "2".  More exceptions ... DB2 SQL error:...
5
6899
by: Daniel Wetzler | last post by:
Dear MSSQL experts, I use MSSQL 2000 and encountered a strange problem wqhile I tried to use a select into statement . If I perform the command command below I get only one dataset which has the described properties. If I use the same statement in a select into statement (see the second select) I get several datasets with the described properties like I didn't use distinct
0
9672
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
10439
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
10215
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...
0
10001
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...
1
7541
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
6783
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();...
0
5437
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
4113
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
3
2920
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.