![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
To get rid of redundant data in a table, my cleint will be providing something like this: IDtokeep Ids to delete 34 24,35,49 12 14,178,1457 54 32,65,68 I have to write a script for each of the above rows which looks like this: ----------------------------------- update sometable set id = 34 where id in (24,35,49) delete from sometable where id in (24,35,49) ----------------------------------- As I said I have to do this for EACH row. Can I somehow automate this or will I need to write to same script for each row (there are about 5000 rows in this audit table) Any help is highly appreciated. Here is the DDL and inserts for the audit table. IF object_id(N'dbo.dataclean','U') is not null DROP TABLE [dbo].[dataclean] GO CREATE TABLE [dataclean] ( [IdTokeep] int NULL , [IdsTodelete] varchar (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ) GO INSERT INTO [dataclean] ([IdTokeep],[IdsTodelete]) VALUES(34,'24,35,49') INSERT INTO [dataclean] ([IdTokeep],[IdsTodelete]) VALUES(12,'14,178,1457') INSERT INTO [dataclean] ([IdTokeep],[IdsTodelete]) VALUES(54,'32,65,68') GO |
#3
| |||
| |||
|
#4
| |||
| |||
|
|
To get rid of redundant data in a table, my cleint will be providing something like this: IDtokeep Ids to delete 34 24,35,49 12 14,178,1457 54 32,65,68 |
|
I have to write a script for each of the above rows which looks like this: ----------------------------------- update sometable set id = 34 where id in (24,35,49) delete from sometable where id in (24,35,49) ----------------------------------- As I said I have to do this for EACH row. Can I somehow automate this or will I need to write to same script for each row (there are about 5000 rows in this audit table) |
![]() |
| Thread Tools | |
| Display Modes | |
| |