Play with the query below until you get righ result. It's easy to convert it to UPDATE after that
DECLARE @test TABLE (complaintID int IDENTITY(1,1), INC char(1), CaseID int, Status varchar(50));
INSERT INTO @test (INC, CaseID, Status)
VALUES
('N', 122003, 'Open: Investigation'),
('N', 122303, 'Open: Investigation'),
(NULL, NULL, NULL),
(NULL, NULL, NULL),
(NULL, NULL, NULL),
('N', 122330, 'Open: Investigation'),
('N', 122331, 'Open: Investigation'),
(NULL, NULL, NULL),
(NULL, NULL, NULL),
('N', 122431, 'Open: Investigation')
SELECT *
FROM @test t1
JOIN @test t21 ON t21.complaintID < t1.complaintID
WHERE t1.CaseID IS NULL AND t21.CaseID IS NOT NULL
AND NOT EXISTS (SELECT 1 FROM @test t22 WHERE t22.CaseID IS NOT NULL AND t22.complaintID < t1.complaintID AND t22.complaintID > t21.complaintID)
>Ok I've added a complaintID column so now I've got
>complaintID INC CaseID Status
>1 N 122303 Open: Investigation
>2 NULL NULL NULL
>3 NULL NULL NULL
>4 NULL NULL NULL
>5 N 122331 Open: Investigation
>Thanks
>
>
>
>>you have to add a column when importing that include that, IDENTITY for example. Otherwise there is no row order in SQL Server
>>
>>>
>>>This has come in from a spreadsheet and its in (I guess) row number order
>>>
>>>>You have to define row ordering in terms of data first. Right now I don't see one.
>>>>
>>>>>I've imported a table and some of the rows have blank values
>>>>>
>>>>>I want to update the empty values of CaseID with the preceding value so in this example all the NULL CaseID will be 122303.
>>>>>I don't mind about the other columns its just the CaseID I want
>>>>>
>>>>>
>>>>>INC CaseID Status
>>>>>N 122303 Open: Investigation
>>>>>NULL NULL NULL
>>>>>NULL NULL NULL
>>>>>NULL NULL NULL
>>>>>N 122331 Open: Investigation
>>>>>
>>>>>
>>>>>Any suggestions on some SQL to do that ?
>>>>>
>>>>>Thanks
>>>>>
>>>>>Nick
--sb--