hi
here is my query
CREATE TABLE [dbo].[CustomCode](
[ID] [int] NULL,
[pcondition] [varchar](50) NULL,
[Pinten] [int] NULL,
[scondition] [varchar](50) NULL,
[sinten] [int] NULL
) ON [PRIMARY]
insert into dbo.CustomCode
select 1,'hf',1,NULL,NULL
UNION ALL
SELECT 1,'CAD',1,NULL,NULL
UNION ALL
SELECT 2,'CA',1,null,null
union ALL
select 2,'ast',1,null,null
union ALL SELECT 3,'HF',2 ,null,null
union ALL SELECT 3,'HF',2,NULL,NULL
union ALL select 3,'HF',2,NULL,NULL
UNION ALL select 3,'HF',2,NULL,NULL
union ALL SELECT 5 ,'hf',3 ,null,null
union ALL SELECT 5, null ,null, 'CA',2
UNION ALL SELECT 5, 'HF',2,NULL,NULL
UNION ALL SELECT 5,NULL,NULL, 'CAD',2
union ALL select 5,'HF',2,NULL,NULL
union all select 6,'AF',3,NULL,NULL
union all select 6,'AST',3,NULL,NULL
UNION ALL select 6,'AST',3,NULL,NULL
union all select 7, 'AF',1,NULL,NULL
union all select 7,'AF',1,NULL,NULL
union all select 7, 'AST',1,NULL,NULL
After executing store porc as below
create procedure [dbo].[customecode]
as
begin
create table #SortSomething
(
pcondition varchar(3),
SortOrder int
)
insert #SortSomething(SortOrder, pcondition)
select 1, 'AF' union all
select 2, 'CA' union all
select 3, 'CAD' union all
select 4, 'AST' union all
select 5, 'hf'
;with duplicateprimarycondition as
(select cc.*, s.SortOrder,
ROW_NUMBER() over(partition by ID, cc.pcondition,cc.pinten order by s.SortOrder) as RowNum
from CustomCode cc
INNER join #SortSomething s on cc.pcondition = s.pcondition)
select * from duplicateprimarycondition
end
result will be
IDpconditionPintensconditionsintenSortOrderRowNum
1CAD1NULLNULL31
1hf1NULLNULL51
2ast1NULLNULL41
2CA1NULLNULL21
3HF2NULLNULL51
3HF2NULLNULL52
3HF2NULLNULL53
3HF2NULLNULL54
5HF2NULLNULL51
5HF2NULLNULL52
5hf3NULLNULL51
6AF3NULLNULL11
6AST3NULLNULL41
6AST3NULLNULL42
7AF1NULLNULL11
7AF1NULLNULL12
7AST1NULLNULL41
i need to modify my stored proc so that
if for that particular ID, for that particular pcondition and pinten if sorder order
comes 1 as two time,it should delete 1 row,
example, here
7AF
1NULL
NULL1
1
7AF1NULLNULL12
it should delete 1 row as two times 1 is coming
plz help