This is a discussion on List when Changes occur within the SQL Server forums, part of the Microsoft SQL Server category; --> Hi I am a newbie to SQL. I have a historical list of digatal points listed by time.ie: 3 ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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. -- Posted via http://dbforums.com |
| ||||
| 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 -- |