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

Comparing records in one table

23
Could someone help me write a query or code that allows me to compare records based on the quarter?

For example, in my table all the records have the PK set as (DCN & Quarter). The DCN is usually the same from one quarter to another. However, 3 fields could change (cost basis, useful life, and start date).

I want to be able to allow a user to enter the 2 quarters they want to compare and then there will be a report showing the changes in DCN's from the 2 selected quarters.

Right now I have multiple tables with the different quarters and I am running somewhat of an unmatched query. This technique is very un-user friendly cus I would need to create a new query with the tables for every combination of quarters I want to compare.

Let me know if I am unclear in explaining this.
Dec 21 '06 #1
10 2646
hibbii
23
Any suggestions on this. Thanks.
Dec 27 '06 #2
willakawill
1,646 1GB
Could someone help me write a query or code that allows me to compare records based on the quarter?

For example, in my table all the records have the PK set as (DCN & Quarter). The DCN is usually the same from one quarter to another. However, 3 fields could change (cost basis, useful life, and start date).

I want to be able to allow a user to enter the 2 quarters they want to compare and then there will be a report showing the changes in DCN's from the 2 selected quarters.

Right now I have multiple tables with the different quarters and I am running somewhat of an unmatched query. This technique is very un-user friendly cus I would need to create a new query with the tables for every combination of quarters I want to compare.

Let me know if I am unclear in explaining this.
Hi. Well this is not going to be an easy answer. We need to start with the table design. You say that the PK is (DCN & Quarter) and that DCN is usually the same. This means that you can only enter 4 rows in the table before you get duplicate values. Unless you are planning to join to one or more other tables in your query we should drop the PK.

What are the data types for quarter and dcn?
Dec 27 '06 #3
hibbii
23
Hi. Well this is not going to be an easy answer. We need to start with the table design. You say that the PK is (DCN & Quarter) and that DCN is usually the same. This means that you can only enter 4 rows in the table before you get duplicate values. Unless you are planning to join to one or more other tables in your query we should drop the PK.

What are the data types for quarter and dcn?
DCN and Quarter are both Text fields. The DCN remains constant with the record for all of time. There are fields in the record that can change but the DCN wont. There is 1 instance of each DCN every quarter this is what makes it unique.

By the way there are about 980 different DCN's in quarter 1. That number could go up or down depending on if we delete a certain DCN or add one. I am only concerned with the ones that are still there in quarter 2 and running a query that will show any changes made from the 2 quarters.
Dec 27 '06 #4
willakawill
1,646 1GB
DCN and Quarter are both Text fields. The DCN remains constant with the record for all of time. There are fields in the record that can change but the DCN wont. There is 1 instance of each DCN every quarter this is what makes it unique.

By the way there are about 980 different DCN's in quarter 1. That number could go up or down depending on if we delete a certain DCN or add one. I am only concerned with the ones that are still there in quarter 2 and running a query that will show any changes made from the 2 quarters.
You can compare two rows in your table using an sql statement to fetch them

Expand|Select|Wrap|Line Numbers
  1. "SELECT DCN FROM [your table name] WHERE [quarter] = '" & UserInput1 _
  2.    & "' OR [quarter] = '" & UserInput2 & "'"
Dec 27 '06 #5
hibbii
23
You can compare two rows in your table using an sql statement to fetch them

Expand|Select|Wrap|Line Numbers
  1. "SELECT DCN FROM [your table name] WHERE [quarter] = '" & UserInput1 _
  2.    & "' OR [quarter] = '" & UserInput2 & "'"
Thanks for that, however, I still dont get what that will do.

How would I add it so that it will show me the adjustments that are made between the 2 DCN's from different quarters? The changes could be made in the costbase, startdate, and/or uselife fields.
Dec 27 '06 #6
willakawill
1,646 1GB
Thanks for that, however, I still dont get what that will do.

How would I add it so that it will show me the adjustments that are made between the 2 DCN's from different quarters? The changes could be made in the costbase, startdate, and/or uselife fields.
Then select all of the fields and do what you need to with the result to show differences:
Expand|Select|Wrap|Line Numbers
  1. "SELECT * FROM [your table name] WHERE [quarter] = '" & UserInput1 _
  2.    & "' OR [quarter] = '" & UserInput2 & "'"
Using the above as a source for a recordset you will be able to perform any operation you like on the fields
Dec 27 '06 #7
hibbii
23
Thanks, let me give it a try. I really never use SQL too often to build my queries just do it off the query design.
Dec 28 '06 #8
Kosmos
153 100+
Hi I am at work but I can give you a little example of how you can make the form more user friendly. So long as you have a simple system like Q3 - 2004, the user will not be confused as to what to enter...I used the following site to get familiar with creating user friendly forms: http://allenbrowne.com/ser-62.html

Go behind the scenes by looking at the code behind on click events and perhaps some of the VBA and SQL will give you some ideas....he explains things well

This site is commercial since it has advertisements and therefore they don't like to use it here...but it's really a great site for reference: http://www.functionx.com/vbaccess/Lesson01.htm

hope this helps
Cheers,
Kosmös
Dec 28 '06 #9
hibbii
23
Then select all of the fields and do what you need to with the result to show differences:
Expand|Select|Wrap|Line Numbers
  1. "SELECT * FROM [your table name] WHERE [quarter] = '" & UserInput1 _
  2.    & "' OR [quarter] = '" & UserInput2 & "'"
Using the above as a source for a recordset you will be able to perform any operation you like on the fields

Hi again. I just tried doing something on my own and have absolutely no idea what it is I am doing. I am having problems setting up how I want the query to do the calculations.

Just a little more background on the table that might allow for you to help me further. The quarters are also sorted by year so they are in "FY06 Q1", "FY06 Q2" etc. format.

Now say when I run the query the parameter boxes pop up, the user enteres FY06 Q1 in the first box and then another box pops up saying "Compare with?" and the user enteres FY06 Q2. I need to write the query to be able to do this. Below is an example of how I do it when the 2 quarters are in different tables.

SELECT DISTINCT ADT_Q3_Complete.DCN, ADT_Q3_Complete.CostBas AS [New Cost Basis], [ADT Calculated Amort Schedule].CostBas AS [Old Cost Basis], ADT_Q3_Complete.[Start Amort Date] AS [New Start Amort Date], [ADT Calculated Amort Schedule].[Start Amort Date] AS [Old Start Amort Date], ADT_Q3_Complete.UseLife AS [New Ueful Life], [ADT Calculated Amort Schedule].UseLife AS [Old Useful Life], ([Old Cost Basis]-[New Cost Basis]) AS [Cost Difference], Abs(DateDiff("d",[Old Start Amort Date],[New Start Amort Date])) AS [Date Difference], [Old Useful Life]-[New Ueful Life] AS [Useful Life Difference]
Dec 28 '06 #10
willakawill
1,646 1GB
Hi again. I just tried doing something on my own and have absolutely no idea what it is I am doing. I am having problems setting up how I want the query to do the calculations.

Just a little more background on the table that might allow for you to help me further. The quarters are also sorted by year so they are in "FY06 Q1", "FY06 Q2" etc. format.

Now say when I run the query the parameter boxes pop up, the user enteres FY06 Q1 in the first box and then another box pops up saying "Compare with?" and the user enteres FY06 Q2. I need to write the query to be able to do this. Below is an example of how I do it when the 2 quarters are in different tables.
do the tables contain fields for different quarters or are the tables named after different quarters and only contain data for a single quarter?

In other words, can I go to one table and get a row of information for each quarter or do I have to go to separate tables to get that info?
Dec 28 '06 #11

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

Similar topics

5
by: Curtis Gilchrist | last post by:
I am required to read in records from a file and store them in descending order by an customer number, which is a c-style string of length 5. I am storing these records in a linked list. My...
2
by: Jason | last post by:
I have a table of 650,000 records associated to contracts. Some of the contracts have multiple records but each contract only has one Active Record (there might be several inactive records). ...
0
by: Jeff Marcum | last post by:
I have two tables that I want to compare and show me the unmatched records. I want to use all fields on both table in the comparison. Here is an example of the fields that are on both tables. ...
4
by: osmethod | last post by:
Hello, I have read many articles about comparing tables, like - loops, delete queries, appending to temp table with index etc Problem: 2 tables T1 & T2. Data is suppposed to be the same in...
4
by: charliej2001 | last post by:
This is my first post on groups and id like to say that already its helped me out loads, but can't quite find what im looking for now I have 3 tables storing information about people; Main, Temp...
2
by: darrel | last post by:
HI there a newbie here in Visual Basic i just wanted to ask something, on how can compare records in a particular field in my table... I'am develop a time scheduling system, its like for example i...
1
by: darrel | last post by:
HI there a newbie here in i just wanted to ask something, on how can compare records in a particular field in my table... I'am develop a time scheduling system, its like for example i have a table...
0
by: NasirMunir | last post by:
I am trying to compare records from oracle table with a table in access. With oraDynaset, I have the option of .findNext function. I can use that to look for matching records from access to oracle....
11
by: jennifersalcido | last post by:
Hello All, I am working with two tables that contain inventory data: 1) INVENTORY contains item_number, description, etc. This data is relatively straight-forward, one record per item_number....
9
by: warrior2009 | last post by:
I have 2 lists (unlinked and unrelated), where one can be called the parent and the other the child with one to many relationship between parent-child. The child table is really big, over a million...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.