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 |
rjhe22
Constraint Violating Yak Guru
283 Posts |
Posted - 2013-08-08 : 11:16:36
|
hiwant to delete records from a table that have the sames dates only want one date in there for each recordsome else wrote this code but its not right. SET ROWCOUNT 1DELETE FROM dbo.TempSyntheticNAV WHERE ( SELECT COUNT(*) FROM dbo.TempSyntheticNAV ee WHERE dbo.TempSyntheticNAV.Date = ee.Date) > 1WHILE (@@rowcount > 0)BEGIN DELETE FROM dbo.TempSyntheticNAV WHERE ( SELECT COUNT(*) FROM dbo.TempSyntheticNAV ee WHERE dbo.TempSyntheticNAV.Date = ee.Date) > 1ENDSET ROWCOUNT 0 what changes will make it do what i want |
|
MuMu88
Aged Yak Warrior
549 Posts |
Posted - 2013-08-08 : 12:08:55
|
Something like this:[CODE]DECLARE @TABLE1 TABLE(ID INT, PET VARCHAR(10), Name VARCHAR(10));INSERT INTO @TABLE1 VALUES(1, 'Cat', 'Newton'),(2, 'Cat', 'Pumpkin'),(3, 'Cat', 'Newton'),(4, 'Dog', 'Roth'),(5, 'Dog', 'Spark'),(6, 'Dog', 'Spark'),(7, 'Dog', 'Buster'),(8, 'Dog', 'Arrow');DELETE D FROM (SELECT ROW_NUMBER() OVER(PARTITION BY Pet, Name ORDER BY ID) RN, Pet, Name from @Table1) D WHERE D.RN > 1;[/CODE] |
 |
|
|
|
|
|
|