试试:USE hospital
GO-- Declare the variables to store the values returned by FETCH.
DECLARE @cPm varchar(40)
DECLARE @cPmNext varchar(40)DECLARE cave_cursor CURSOR DYNAMIC
FOR
SELECT 品名 FROM dbo.temly_7
--GROUP BY 品名
--HAVING COUNT(品名)>1
--ORDER BY 品名
OPEN cave_cursor-- Perform the first fetch and store the values in variables.
-- Note: The variables are in the same order as the columns
-- in the SELECT statement. FETCH NEXT FROM cave_cursor 
INTO @cPm
FETCH NEXT FROM cave_cursor 
INTO @cPmNext
-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN
IF @cPmNext=@cPm
DELETE FROM dbo.temly_7 where CURRENT of cave_cursor
ELSE
SET @cPm=@cPmNext
FETCH NEXT FROM cave_cursor
INTO @cPmNext
END
CLOSE cave_cursor
DEALLOCATE cave_cursor
GO