473,796 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Querying 1 Day Old Data ( Date )

36 New Member
My table looks like the following

[PartNumber], [FromStep],[ToStep],[MovedDateValue]
Ex.
[Fish], [Step1], [Step2],[1/2/2007]
[Fish[, [Step2], [Step3],[1/3/2007]

It contains all the [FromStep] and [ToStep] that [PartNumber] goes through in the past 3 months.

How would I go about querying for all [PartNumber]'s that took more than 1 day to move from Step 1 to Step 2?... so on and so forth.

I tried the DateDiff Function and the numbers did not work.
Jan 10 '08 #1
3 1347
FishVal
2,653 Recognized Expert Specialist
Hi, there.

You may try to join the table with itself on records where [PartNumber] is the same and [ToStep] in one table alias is the same as [FromStep] in another. Thus you will obtain dataset with records containing dates of sequential steps, then you may use DateDiff() function. Or you may include day difference in JOIN criteria.

Something like this.

Expand|Select|Wrap|Line Numbers
  1. SELECT t1.[PartNumber], t1.[MovedDateValue], t2.[MovedDateValue] FROM [YourTableName] AS t1 INNER JOIN [YourTableName] AS t2 ON t1.[PartNumber]=t2.[PartNumber] AND t1.[ToStep]=t2.[FromStep] AND DateDiff("d", t1.[MovedDateValue], t2.[MovedDateValue]) > 1;
  2.  
Regards,
Fish
Jan 10 '08 #2
ilikebirds
36 New Member
If I only had half the smarts you did!
That seem to do the trick. Thanks.

Now if I add:

WHERE t1.[to_order_step_n um]="Step1";

To the end, I will be able to search specific steps that are =>1, correct?
Jan 10 '08 #3
FishVal
2,653 Recognized Expert Specialist
If I only had half the smarts you did!
That seem to do the trick. Thanks.

Now if I add:

WHERE t1.[to_order_step_n um]="Step1";

To the end, I will be able to search specific steps that are =>1, correct?
If you ever have records where [ToStep]="Step1", then you will get records for Step1->Step2 movements.
Jan 10 '08 #4

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

Similar topics

3
1833
by: Keith | last post by:
I am fairly new to SQL so sorry if this is a really dumb question. I have a small (still) SQL database, which I am trying to query from an ASP page. The field I am querying is of DATETIME data type, and is populated automatically using the GetDate() function as a default value. When I try and search on this field, using a date/time in the format dd/mm/yyyy hh:mm:ss as the search criteria, it fails with the following
7
32975
by: Marc Pelletier | last post by:
Hello, I have a table with a Day field, defined as smalldatetime. I am filling it from a CSharp application with the following code: DataRow r = dtStaDays.NewRow(); r= station_ID; r = sd.Date; r = rangeTide; etc.
7
1536
by: ndn_24_7 | last post by:
Hello all, I'm trying to run a query to make a report. My database is a incident reporting database. I'm tryng to make a monthy report for incidents. The field I need to query in the date field which is a nvarchar in the form of 01/01/04 and 01/01/2004. I ran a query that looks like this: SELECT incident, doccur, ID FROM dbo.Incident WHERE (doccur between '01/01/2004' and '01/31/2004') I get some results that look like...
6
2657
by: Greg | last post by:
I am working on a project that will have about 500,000 records in an XML document. This document will need to be queried with XPath, and records will need to be updated. I was thinking about splitting up the XML into several XML documents (perhaps 50,000 per document) to be more efficient but this will make things a lot more complex because the searching needs to go accross all 500,000 records. Can anyone point me to some best practices...
3
2021
by: AndyBell | last post by:
Hi all! I have an Access 2000 database for the Habiat for Humanity where I work. This is the second database I have written and it gets a bit more complex each time... I have learned much and read much over the last few months and have found leads to the answers to several other problems I have encountered with a Google search of past posts/threads. SO thank you for the help already rendered even though you didn't know!! My problem...
4
2497
by: Stewart Allen | last post by:
I'm trying to filter a table that has 2 date fields, the first date will always have a value but the second will only occasionally has a value. Each date field also has a corresponding text field to record the record's status. Sample data: *tblTest* Model Parts CDate CStatus RDate RStatus 616 $359.79 03-Nov-03 C
5
2377
by: Shane | last post by:
I wonder if someone has any ideas about the following. I am currently producing some reports for a manufacturing company who work with metal. A finished part can contain multiple sub-parts to make up the finished part. The sub-parts can also be made up of sub-parts and those sub-parts can also be made up of sub-parts etc etc. All parts are contained within the same table and I have a seperate table
0
2626
by: roiavidan | last post by:
Hi, I'm having a bit of a problem with a small application I wrote in C#, which uses an Access database (mdb file) for storing financial data. After looking for a similiar topic and failing to find one, I'm posting the question in hope some one of you guys out there will have the answer for me...! I'll start with what I have, then I'll continue to the problem itself.
2
1482
by: Steven Cheng [MSFT] | last post by:
Hi Cj, I also noticed that the "Act" variable here seems hasn't been declared(or declared anywhere else?). I've try building the same code and got the same result and the "Operator '+' cannot be applied to operands of type 'string' " error does pointing to the "Act.Trim" which should be of method call syntax such as Act.Trim() After change it, that error is eliminated.
4
1379
by: mcmahon | last post by:
Hi, I have a MS Access DB with a query that I need to display in vb but am not too sure on how to go about it. The query has some criteria - i.e you have to input a date to run the query. I think that's a parameter in vb...... Well I've been playing around with it for some time now but amn't really getting anywhere. Could ye recommend any good tutorial or link as to how to do it? Here's the code that I've been working on: Imports...
0
9673
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
9524
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10449
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...
1
10168
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
10003
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...
0
5440
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
5568
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4114
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
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.