Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
mdhingra01
Posting Yak Master
179 Posts |
Posted - 2004-11-22 : 16:10:37
|
| I am looking for a way to write a query that will allow me to compare records and accordingly assign a value.For example:I have Table A which has the following columns:ExtractDate,ID,HireDate,StatusCodeI need to write a query that will build TABLE B with columns:ID,HireDate,StatusCode,StatusStartDate,StatusEndDateThe query needs to look at all the values for a Table A.ID and determine when the Table A.Status changed. The query needs to then insert a record into Table B with a record for each of the distinct StatusCode values in Table A. Therefore, in this sample data we see:Extracted ID HIREDATE STATUS 20030715 001 20010918 A20030815 001 20010918 A20030915 001 20010918 A20031015 001 20010918 P20031118 001 20010918 P20031214 001 20010918 P20040115 001 20010918 AI would want the following in Table B to show up:ID HIREDATE STATUS STATUSSTART STATUSEND001 20010918 A 20030715 20031015 001 20010918 P 20031015 20040115 001 20010918 A 20040115Thanks fr any help on this. |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2004-11-22 : 17:08:12
|
| There really is no "next". The order of rows in a database is meaningless...well, except for the clustered index...you need to order the data..You could do SELECT * FROM yourTable And you could get different resultsYou need something that relates the rows of data to each other.Got anything like that?Brett8-) |
 |
|
|
|
|
|