Please read the first article in my signature about posting these types of questions to the forum. I have added the tables and some sample data for you and using the window function ROW_NUMBER() to solve the issue. Let me know if this works for you:drop table ATTRIBUTE_TRANS;
drop table WS_Table;
go
create table ATTRIBUTE_TRANS (
ID_NUM int
,Attrib_seqint)
create table WS_Table (
id_num int
,attribute_cde int
);
insert ATTRIBUTE_TRANS
values (1,2)
,(2,1);
insert WS_Table
values (1,1)
, (2,1)
, (1,2)
, (3,1);
SELECT w.id_num,
ISNULL((SELECT MAX(a.ATTRIB_SEQ)
FROM dbo.ATTRIBUTE_TRANS a
WHERE w.ID_NUM = a.ID_NUM
GROUP BY a.ID_NUM
)+ROW_NUMBER() over (partition by w.id_num order by w.id_num), 1) AS MAX_SEQ_NUM
,attribute_cde
,'ADMIN'
,'attribute_insert'
,CURRENT_TIMESTAMP
FROM WS_Table w
EDIT: I forgot to add partition by in ROW_NUMBER