473,903 Members | 4,731 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help on a query

I have a table that stores job milestone dates. The 2 milestones I am
interested in are "Ship Date" TypeID 1 and "Revised Ship Date" TypeID 18.
All jobs have TypeID 1 only some jobs have TypeID 18. I need a query that
will return the c date for TypeID 18 if it exist else the date for TypeID 1,
for all jobs.

the table structure is the following

Job
TypeID
DateEst

I have the following but it only returns the latest date but sometimes
TypeID 18's date if less then TypeID 1's

SELECT DISTINCTROW tblJobDate.Job, Max(tblJobDate. DateEst) AS MaxOfDateEst
FROM tblJobDate
WHERE (((tblJobDate.T ypeID)=1 Or (tblJobDate.Typ eID)=18))
GROUP BY tblJobDate.Job
ORDER BY tblJobDate.Job;


Nov 12 '05 #1
6 2431
If the "ship date" and "revised ship date" were two different fields you could set
criteria for "ship date" to be where "revised ship date" Is Null. This would also have the
advantage of giving you both dates for comparison later to see how well you are meeting
your initial ship dates.

If you have the dates in 2 different fields, but are just using a 3rd field to indicate
which of the 2 dates you are using, you could still use the criteria mentioned above.
However, if this is the case, the 3rd field really isn't needed since you could calculate
which of the two IDs it is by using the criteria mentioned. The general rule of thumb is
"don't store anything you can calculate." Now, what might be a good use for a 3rd field is
a counter to see how many times the "revised ship date" was changed.

--
Wayne Morgan
"paii" <pa**@packairin c.com> wrote in message news:vn******** ****@corp.super news.com...
I have a table that stores job milestone dates. The 2 milestones I am
interested in are "Ship Date" TypeID 1 and "Revised Ship Date" TypeID 18.
All jobs have TypeID 1 only some jobs have TypeID 18. I need a query that
will return the c date for TypeID 18 if it exist else the date for TypeID 1,
for all jobs.

the table structure is the following

Job
TypeID
DateEst

I have the following but it only returns the latest date but sometimes
TypeID 18's date if less then TypeID 1's

SELECT DISTINCTROW tblJobDate.Job, Max(tblJobDate. DateEst) AS MaxOfDateEst
FROM tblJobDate
WHERE (((tblJobDate.T ypeID)=1 Or (tblJobDate.Typ eID)=18))
GROUP BY tblJobDate.Job
ORDER BY tblJobDate.Job;

Nov 12 '05 #2
Thank you for your input.

The dates are in different record because they are they are only 2 "Very
important dates" in a list of milestones needed to complete a job. I could
put all the milestones in the same record but then I would have to change
the table structure anytime I wanted to add a new milestone.

Maybe my structure is wrong, Any input on something better would be very
much appreciated.
"Wayne Morgan" <co************ *************** @hotmail.com> wrote in message
news:2r******** *********@newss vr33.news.prodi gy.com...
If the "ship date" and "revised ship date" were two different fields you could set criteria for "ship date" to be where "revised ship date" Is Null. This would also have the advantage of giving you both dates for comparison later to see how well you are meeting your initial ship dates.

If you have the dates in 2 different fields, but are just using a 3rd field to indicate which of the 2 dates you are using, you could still use the criteria mentioned above. However, if this is the case, the 3rd field really isn't needed since you could calculate which of the two IDs it is by using the criteria mentioned. The general rule of thumb is "don't store anything you can calculate." Now, what might be a good use for a 3rd field is a counter to see how many times the "revised ship date" was changed.

--
Wayne Morgan
"paii" <pa**@packairin c.com> wrote in message

news:vn******** ****@corp.super news.com...
I have a table that stores job milestone dates. The 2 milestones I am
interested in are "Ship Date" TypeID 1 and "Revised Ship Date" TypeID 18. All jobs have TypeID 1 only some jobs have TypeID 18. I need a query that will return the c date for TypeID 18 if it exist else the date for TypeID 1, for all jobs.

the table structure is the following

Job
TypeID
DateEst

I have the following but it only returns the latest date but sometimes
TypeID 18's date if less then TypeID 1's

SELECT DISTINCTROW tblJobDate.Job, Max(tblJobDate. DateEst) AS MaxOfDateEst FROM tblJobDate
WHERE (((tblJobDate.T ypeID)=1 Or (tblJobDate.Typ eID)=18))
GROUP BY tblJobDate.Job
ORDER BY tblJobDate.Job;


Nov 12 '05 #3
To continue the way you are going, the only thing I can think of is to create a query that
will retrieve all of the records that have a "revised delivery date". Use this query and
the current table in an "unmatched query" using the field that is common to all records of
the same job as the field to not match. You would then take the results of this query and
the first one and make a "union query" to merge them together. Perhaps a SQL guru could
come up with something smoother, something keeps telling me that a subquery might be able
to do this, but I haven't figured out how yet.

Yes, I think putting them all in the same record for the same job would be easier and just
add a field if you come up with a new item for jobs to meet. Do these new items happen
often?

--
Wayne Morgan
"paii" <pa**@packairin c.com> wrote in message news:vn******** ****@corp.super news.com...
Thank you for your input.

The dates are in different record because they are they are only 2 "Very
important dates" in a list of milestones needed to complete a job. I could
put all the milestones in the same record but then I would have to change
the table structure anytime I wanted to add a new milestone.

Maybe my structure is wrong, Any input on something better would be very
much appreciated.
"Wayne Morgan" <co************ *************** @hotmail.com> wrote in message
news:2r******** *********@newss vr33.news.prodi gy.com...
If the "ship date" and "revised ship date" were two different fields you

could set
criteria for "ship date" to be where "revised ship date" Is Null. This

would also have the
advantage of giving you both dates for comparison later to see how well

you are meeting
your initial ship dates.

If you have the dates in 2 different fields, but are just using a 3rd

field to indicate
which of the 2 dates you are using, you could still use the criteria

mentioned above.
However, if this is the case, the 3rd field really isn't needed since you

could calculate
which of the two IDs it is by using the criteria mentioned. The general

rule of thumb is
"don't store anything you can calculate." Now, what might be a good use

for a 3rd field is
a counter to see how many times the "revised ship date" was changed.

--
Wayne Morgan
"paii" <pa**@packairin c.com> wrote in message

news:vn******** ****@corp.super news.com...
I have a table that stores job milestone dates. The 2 milestones I am
interested in are "Ship Date" TypeID 1 and "Revised Ship Date" TypeID 18. All jobs have TypeID 1 only some jobs have TypeID 18. I need a query that will return the c date for TypeID 18 if it exist else the date for TypeID 1, for all jobs.

the table structure is the following

Job
TypeID
DateEst

I have the following but it only returns the latest date but sometimes
TypeID 18's date if less then TypeID 1's

SELECT DISTINCTROW tblJobDate.Job, Max(tblJobDate. DateEst) AS MaxOfDateEst FROM tblJobDate
WHERE (((tblJobDate.T ypeID)=1 Or (tblJobDate.Typ eID)=18))
GROUP BY tblJobDate.Job
ORDER BY tblJobDate.Job;



Nov 12 '05 #4
I did not think of the unlatch query followed by a Union, I am going to look
at that. We need this type of table structure our company is constantly
updating its procedures, I recently doubled the number of possible
milestones any job can have without changing the table structures or any
existing reports or forms.

"Wayne Morgan" <co************ *************** @hotmail.com> wrote in message
news:3l******** **********@news svr31.news.prod igy.com...
To continue the way you are going, the only thing I can think of is to create a query that will retrieve all of the records that have a "revised delivery date". Use this query and the current table in an "unmatched query" using the field that is common to all records of the same job as the field to not match. You would then take the results of this query and the first one and make a "union query" to merge them together. Perhaps a SQL guru could come up with something smoother, something keeps telling me that a subquery might be able to do this, but I haven't figured out how yet.

Yes, I think putting them all in the same record for the same job would be easier and just add a field if you come up with a new item for jobs to meet. Do these new items happen often?

--
Wayne Morgan
"paii" <pa**@packairin c.com> wrote in message

news:vn******** ****@corp.super news.com...
Thank you for your input.

The dates are in different record because they are they are only 2 "Very
important dates" in a list of milestones needed to complete a job. I could put all the milestones in the same record but then I would have to change the table structure anytime I wanted to add a new milestone.

Maybe my structure is wrong, Any input on something better would be very
much appreciated.
"Wayne Morgan" <co************ *************** @hotmail.com> wrote in message news:2r******** *********@newss vr33.news.prodi gy.com...
If the "ship date" and "revised ship date" were two different fields you
could set
criteria for "ship date" to be where "revised ship date" Is Null. This

would also have the
advantage of giving you both dates for comparison later to see how
well you are meeting
your initial ship dates.

If you have the dates in 2 different fields, but are just using a 3rd

field to indicate
which of the 2 dates you are using, you could still use the criteria

mentioned above.
However, if this is the case, the 3rd field really isn't needed since
you could calculate
which of the two IDs it is by using the criteria mentioned. The
general rule of thumb is
"don't store anything you can calculate." Now, what might be a good
use for a 3rd field is
a counter to see how many times the "revised ship date" was changed.

--
Wayne Morgan
"paii" <pa**@packairin c.com> wrote in message

news:vn******** ****@corp.super news.com...
> I have a table that stores job milestone dates. The 2 milestones I
am > interested in are "Ship Date" TypeID 1 and "Revised Ship Date" TypeID 18.
> All jobs have TypeID 1 only some jobs have TypeID 18. I need a query

that
> will return the c date for TypeID 18 if it exist else the date for

TypeID 1,
> for all jobs.
>
> the table structure is the following
>
> Job
> TypeID
> DateEst
>
> I have the following but it only returns the latest date but

sometimes > TypeID 18's date if less then TypeID 1's
>
> SELECT DISTINCTROW tblJobDate.Job, Max(tblJobDate. DateEst) AS

MaxOfDateEst
> FROM tblJobDate
> WHERE (((tblJobDate.T ypeID)=1 Or (tblJobDate.Typ eID)=18))
> GROUP BY tblJobDate.Job
> ORDER BY tblJobDate.Job;
>
>
>
>



Nov 12 '05 #5
I created a query to select all records with TypeID = 18
Then created a query to select all records with TypeID = 1 that were not in
the 1st query.
Then created a union query to combine the 1st 2 queries.

This appears to work. I don't now how efficient it is to pull from the table
3 time.

"paii" <pa**@packairin c.com> wrote in message
news:vn******** ****@corp.super news.com...
I did not think of the unlatch query followed by a Union, I am going to look at that. We need this type of table structure our company is constantly
updating its procedures, I recently doubled the number of possible
milestones any job can have without changing the table structures or any
existing reports or forms.

"Wayne Morgan" <co************ *************** @hotmail.com> wrote in message news:3l******** **********@news svr31.news.prod igy.com...
To continue the way you are going, the only thing I can think of is to create a query that
will retrieve all of the records that have a "revised delivery date". Use this query and
the current table in an "unmatched query" using the field that is common to all records of
the same job as the field to not match. You would then take the results

of this query and
the first one and make a "union query" to merge them together. Perhaps a SQL guru could
come up with something smoother, something keeps telling me that a

subquery might be able
to do this, but I haven't figured out how yet.

Yes, I think putting them all in the same record for the same job would

be easier and just
add a field if you come up with a new item for jobs to meet. Do these
new items happen
often?

--
Wayne Morgan
"paii" <pa**@packairin c.com> wrote in message news:vn******** ****@corp.super news.com... Thank you for your input.

The dates are in different record because they are they are only 2 "Very important dates" in a list of milestones needed to complete a job. I could put all the milestones in the same record but then I would have to change the table structure anytime I wanted to add a new milestone.

Maybe my structure is wrong, Any input on something better would be very much appreciated.
"Wayne Morgan" <co************ *************** @hotmail.com> wrote in message news:2r******** *********@newss vr33.news.prodi gy.com...
> If the "ship date" and "revised ship date" were two different fields you could set
> criteria for "ship date" to be where "revised ship date" Is Null. This would also have the
> advantage of giving you both dates for comparison later to see how well you are meeting
> your initial ship dates.
>
> If you have the dates in 2 different fields, but are just using a 3rd field to indicate
> which of the 2 dates you are using, you could still use the criteria
mentioned above.
> However, if this is the case, the 3rd field really isn't needed since you
could calculate
> which of the two IDs it is by using the criteria mentioned. The general rule of thumb is
> "don't store anything you can calculate." Now, what might be a good use for a 3rd field is
> a counter to see how many times the "revised ship date" was changed.
>
> --
> Wayne Morgan
>
>
> "paii" <pa**@packairin c.com> wrote in message
news:vn******** ****@corp.super news.com...
> > I have a table that stores job milestone dates. The 2 milestones I am > > interested in are "Ship Date" TypeID 1 and "Revised Ship Date" TypeID 18.
> > All jobs have TypeID 1 only some jobs have TypeID 18. I need a
query that
> > will return the c date for TypeID 18 if it exist else the date for
TypeID 1,
> > for all jobs.
> >
> > the table structure is the following
> >
> > Job
> > TypeID
> > DateEst
> >
> > I have the following but it only returns the latest date but

sometimes > > TypeID 18's date if less then TypeID 1's
> >
> > SELECT DISTINCTROW tblJobDate.Job, Max(tblJobDate. DateEst) AS
MaxOfDateEst
> > FROM tblJobDate
> > WHERE (((tblJobDate.T ypeID)=1 Or (tblJobDate.Typ eID)=18))
> > GROUP BY tblJobDate.Job
> > ORDER BY tblJobDate.Job;
> >
> >
> >
> >
>
>



Nov 12 '05 #6
Union queries are not efficient, but they work, which is sometimes more important. Glad
you got it going.

--
Wayne Morgan
"paii" <pa**@packairin c.com> wrote in message news:vn******** ****@corp.super news.com...
I created a query to select all records with TypeID = 18
Then created a query to select all records with TypeID = 1 that were not in
the 1st query.
Then created a union query to combine the 1st 2 queries.

This appears to work. I don't now how efficient it is to pull from the table
3 time.

Nov 12 '05 #7

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

Similar topics

2
3062
by: lawrence | last post by:
I've been bad about documentation so far but I'm going to try to be better. I've mostly worked alone so I'm the only one, so far, who's suffered from my bad habits. But I'd like other programmers to have an easier time understanding what I do. Therefore this weekend I'm going to spend 3 days just writing comments. Before I do it, I thought I'd ask other programmers what information they find useful. Below is a typical class I've...
9
3145
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use SUBSTRING(ProductName, 1, CHARINDEX('(', ProductName)-2). I can get this result, but I had to use several views (totally inefficient). I think this can be done in one efficient/fast query, but I can't think of one. In the case that one query is not...
3
1870
by: pw | last post by:
Hi, I am having a mental block trying to figure out how to code this. Two tables: "tblQuestions" (fields = quesnum, questype, question) "tblAnswers" (fields = clientnum, quesnum, questype, answer) They are related by quesnum and questype. There are records in
7
2378
by: K. Crothers | last post by:
I administer a mechanical engineering database. I need to build a query which uses the results from a subquery as its input or criterion. I am attempting to find all of the component parts of which a part may be composed. I have a table of parts and their subparts. The problem is that each of those subparts may be composed of smaller component parts. The subpart would then be listed in the Part field linked to each of its subparts in...
3
10690
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems that are hard to find. The main problem I am having right now is that I have a report that is sorted by one of these lookup fields and it only displays the record's ID number. When I add the source table to the query it makes several records...
10
2604
by: L. R. Du Broff | last post by:
I own a small business. Need to track a few hundred pieces of rental equipment that can be in any of a few dozen locations. I'm an old-time C language programmer (UNIX environment). If the only tool you know how to use is a hammer, every problem tends to look like a nail. That said, I could solve my problem in C, but it's not the right tool. I need to come into the Windows world, and I need to get this done in Access or something...
1
1716
by: write2ashokkumar | last post by:
hi... i have the table like this, Table Name : sample Total Records : 500000 (Consider like this) Sample Records: id ------------ name
1
1560
by: write2ashokkumar | last post by:
hi... i have the table like this, Table Name : sample Total Records : 500000 (Consider like this) Sample Records: ----------------
1
1276
by: write2ashokkumar | last post by:
hi... i have the table like this, Table Name : sample Total Records : 500000 (Consider like this) Sample Records: ----------------
3
2568
by: pbd22 | last post by:
Hi. I need some help with structuring my query strings. I have a form with a search bar and some links. Each link is a search type (such as "community"). The HREF for the link's anchor looks like the following: <a href="?searchtype=2">Community</a>
0
11285
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
10878
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
10986
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
10501
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
8049
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
7208
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
5894
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...
0
6094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4727
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

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.