Groups | Blog | Home
all groups > sql server (alternate) > august 2003 >

sql server (alternate) : List when Changes occur


Speaker
8/28/2003 9:15:21 AM

Hi I am a newbie to SQL.

I have a historical list of digatal points listed by time.ie: 3 fields
PointName;Date/Time;State.

I need to return a list of When a specific point chsnges state.



For example a list everytime Point A transitions to State 1.



Any help is appreciated.


--
David Portas
8/28/2003 5:49:50 PM
Assuming your table looks like this:

CREATE TABLE PointStates (pointname CHAR(1), dt DATETIME, state INTEGER NOT
NULL, PRIMARY KEY (pointname,dt))

You can use this query:

SELECT DISTINCT
MIN(B.dt)
FROM PointStates AS A
JOIN PointStates AS B
ON A.pointname = B.pointname
AND A.dt < B.dt
AND A.state<>B.state
GROUP BY A.pointname, A.dt

--
David Portas
------------
Please reply only to the newsgroup
--

AddThis Social Bookmark Button