fikir
Programmer
- Jun 25, 2007
- 86
Hello,
I have a table which has redundent records, I want to update those records to null but leaving one
tbl
id name
1 aa
1 aa
1 aa
2 bb
2 bb
3 cc
I wrote this query to do the task but my query statts updating from the first one and leaving the last record but I want it to be the other way, leaving the first one and updating the rest
how can I modify this to solve my problem
thanks
I have a table which has redundent records, I want to update those records to null but leaving one
tbl
id name
1 aa
1 aa
1 aa
2 bb
2 bb
3 cc
I wrote this query to do the task but my query statts updating from the first one and leaving the last record but I want it to be the other way, leaving the first one and updating the rest
Code:
SET ROWCOUNT 1
SELECT 1
WHILE (@@ROWCOUNT > 0)
BEGIN
UPDATE TBL
SET NAME = NULL
FROM TBL T
WHERE 1 < (SELECT COUNT(*) FROM TBL T2
WHERE T.ID = T2.ID
AND T.NAME = T2.NAME )
END
SET ROWCOUNT 0
how can I modify this to solve my problem
thanks