![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
#4
| |||
| |||
|
|
Does sqlserver quarantee a particular order of the rows based just on the order of the rows as they were being imported (or the order they were inserted)? |
#5
| |||
| |||
|
|
Here is one solution: CREATE TABLE Foo ( * keycol INT NOT NULL PRIMARY KEY, * datacol VARCHAR(10)); INSERT INTO Foo VALUES(1, 'ABC'); INSERT INTO Foo VALUES(2, NULL); INSERT INTO Foo VALUES(3, NULL); INSERT INTO Foo VALUES(4, NULL); INSERT INTO Foo VALUES(5, 'DEF'); INSERT INTO Foo VALUES(6, NULL); INSERT INTO Foo VALUES(7, NULL); SELECT A.keycol, COALESCE(A.datacol, B.datacol) AS datacol FROM Foo AS A JOIN Foo AS B * *ON A.keycol >= B.keycol WHERE B.datacol IS NOT NULL * *AND NOT EXISTS(SELECT * * * * * * * * * * FROM Foo AS C * * * * * * * * * WHERE C.keycol > B.keycol * * * * * * * * * * AND C.keycol <= A.keycol * * * * * * * * * * AND C.datacol IS NOT NULL); /* keycol * * *datacol ----------- ---------- 1 * * * * * ABC 2 * * * * * ABC 3 * * * * * ABC 4 * * * * * ABC 5 * * * * * DEF 6 * * * * * DEF 7 * * * * * DEF */ -- Plamen Ratchevhttp://www.SQLStudio.com |
#6
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |