> This is what I want to do with the data table below. I only want it to show one id for each issue. ( ie, 4001 only once, 4002 only once, etc. But only the one with the latest date and time)
Ie. 4001 should only be in the table once, with the latest date - which should be : 4001 09/12/2003 17:12:09 (as I only want to show the last time the id was updated - do you get me now )
Ie. 4002 should show only 4002 11/12/2003 15:25:13
id hs_change_date hs_change_time 4001 27/10/2003 10:38:27 4001 09/12/2003 14:43:58 4001 09/12/2003 17:12:09 4002 27/10/2003 10:56:28 4002 09/12/2003 14:44:11 4002 11/12/2003 15:25:13 4003 27/10/2003 11:13:12 4003 09/12/2003 14:44:21 4003 10/12/2003 10:48:02 4003 10/12/2003 13:25:09 4004 27/10/2003 11:28:09 4004 09/12/2003 14:44:29 4004 09/12/2003 17:18:28 4005 27/10/2003 15:55:40 4005 28/10/2003 10:18:24 4006 27/10/2003 15:59:47 4006 28/10/2003 10:18:38 4006 09/12/2003 14:44:40 4006 09/12/2003 16:47:15 3 9629
What data types are you using here? SQLServer DATETIME stores both data and
time in the same column so I don't understand why you appear to have
separate columns. It helps to clarify your requirements if you include DDL
with your questions.
Assuming you define your table with a single DATETIME column you can get the
result you require quite easily:
CREATE TABLE Sometable (id INTEGER, hs_change_dt DATETIME, PRIMARY KEY /*
??? */ (id, hs_change_dt))
SELECT id, MAX(hs_change_d t) AS hs_change_dt
FROM Sometable
GROUP BY id
--
David Portas
SQL Server MVP
--
The database is already setup with two separate columns - one for
date and one for time. see below I only want it to show one id for each issue. ( ie, 4001 only once, 4002 only once, etc. But only the one with the latest date and time)
Ie. 4001 should only be in the table once, with the latest date - which should be : 4001 09/12/2003 17:12:09 (as I only want to show the last time the id was updated - do you get me now )
Ie. 4002 should show only 4002 11/12/2003 15:25:13
Do you get me?
id hs_change_date hs_change_time 4001 27/10/2003 10:38:27 4001 09/12/2003 14:43:58 4001 09/12/2003 17:12:09 4002 27/10/2003 10:56:28
"David Portas" <RE************ *************** *@acm.org> wrote in message news:<7_******* *************@g iganews.com>... What data types are you using here? SQLServer DATETIME stores both data and time in the same column so I don't understand why you appear to have separate columns. It helps to clarify your requirements if you include DDL with your questions.
Assuming you define your table with a single DATETIME column you can get the result you require quite easily:
CREATE TABLE Sometable (id INTEGER, hs_change_dt DATETIME, PRIMARY KEY /* ??? */ (id, hs_change_dt))
SELECT id, MAX(hs_change_d t) AS hs_change_dt FROM Sometable GROUP BY id
> The database is already setup with two separate columns - one for date and one for time. see below
OK, but what are the data types? You still haven't told us and it makes a
difference to the solution. I'll assume you have DATETIME for the date and
CHAR(8) for the time.
CREATE TABLE Sometable (id INTEGER, hs_change_date DATETIME, hs_change_time
CHAR(8) NOT NULL, PRIMARY KEY (id, hs_change_date, hs_change_time) )
SELECT id,
CAST(DATEDIFF(D ,0,hs_change_dt ) AS DATETIME) AS hs_change_date,
CONVERT(CHAR(8) ,hs_change_dt,1 08) AS hs_change_time
FROM
(SELECT id,
MAX(CAST(CONVER T(CHAR(11),hs_c hange_date,126) +
hs_change_time AS DATETIME))
FROM Sometable
GROUP BY id) AS T (id,hs_change_d t)
This seems like a pointless design that wastes at least 8 bytes of storage
per row and worst of all it makes the data very difficult to maipulate (see
above and compare it with my first answer).
--
David Portas
SQL Server MVP
-- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Gleep |
last post by:
Hey Guys,
I've got a table called Outcomes. With 3 columns and 15 rows
1st col 2nd col 3rdcol
outcome date price
There are 15 rows for each record, each row accounts for a different type of outcome
I'm having trouble with MySQL date comparison. I'm looking for some kind of query that will compare
the all date column and only give me the latest date. Then once I have it, ...
|
by: Robert Hathaway |
last post by:
COMP.OBJECT FAQ
Version II Beta now Available
http://www.objectfaq.com/oofaq2
==================================================
- Latest Important Information on Object Technology - What's New Page
- What professionals *must keep up on* in rapidly changing environment
- Available on Homepage, email notification on updates now available
- Good Resource Site - Latest in Object Technology
- Complete Coverage of Object Orientation
- Up to...
|
by: Clint Norton |
last post by:
Hi all,
I'm a student currently in the beginning of my master's degree and
I'm searching for an interesting open source project written in Python
to contribute to.
I have worked as a programmer for the past few years (mostly in
academia but also as a typical full time code monkey in a commercial
company), some of it in python, some in Java (commercial companies
really seem to like Java).
Anyway, which python projects would be a good...
|
by: M.Stanley |
last post by:
Hi,
I have a problem..I'm doing a specific query where I'm joining fields
from a table with appednded data (there are duplicate records, except
for the date/time), and another query. I want the results of the new
query to return ALL of the matches, and only the latest record when it
finds duplicates. Performing a return top values doesn't work because
it doesn't return all of the matchs, using LAST in the date field
criteria only...
|
by: Fatz |
last post by:
I have a table with a Date Field. This field is populated with the
date and time an entry was made to the table.
I am looking to create a query that pulls only the most recent record.
I am pretty sure this is done with the DMax function but I don't know
how to build the code.
Date field is named "Date"
Table is named "ABC"
| |
by: clare at snyder.on.ca |
last post by:
I have a SQL query I need to design to select name and email addresses
for policies that are due and not renewed in a given time period. The
problem is, the database keeps the information for every renewal in
the history of the policyholder.
The information is in 2 tables, policy and customer, which share the
custid data. The polno changes with every renewal Renewals in 2004
would be D, 2005 S, and 2006 L. polexpdates for a given customer...
|
by: Eugene |
last post by:
Hi all,
I have the following table
Name Date Wish Valid
Name is person's name, date defaults to getdate() and is never
assigned directly (datetime field), Wish is some message, and Valid is
bit, 1 indicates if the wish is the latest, and therefore valid. All
previous wishes are kept in database, and are "invalidated" by setting
|
by: Kassimu |
last post by:
Hi guys out there,
There is this database Iam creating, I have a table with 40 fields among which there are Date/time, Text, Number, Memo and Yes/No fields and I have created the form bound to that tabe. I have also created Unbound form (for searching purpose) which is similar in layout with the bound one; in this search form the user will fill-in the keywords in as many text boxes as he wish to narrow down the search. The search results are...
|
by: Yasin |
last post by:
Walt <walt@boatnerd.com.invalidwrote in message news:<3F0C5BA9.DB809458@boatnerd.com.invalid>...
You can use below sql for your result
select * from test;
PERSON_ID DAT TIME CODE
--------- -------- ----- ----------
1 26.04.98 07:00 First one
2 08.07.03 16:00 Second
|
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...
|
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...
| |
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...
|
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,...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |