alter procedure sp_contacts
(
@Category1Code nvarchar(20),
@Category2Code nvarchar(20),
@FirstName nvarchar(20),
@LastName nvarchar(20)
)
AS
begin
Declare @CategoryName1 varchar(20)
Declare @CategoryName2 varchar(20)
select @CategoryName1= CategoryName from Category1Code where Category1Code = @Category1Code
select @CategoryName2= CategoryName from Category2Code where Category2Code = @Category2Code and Category1Code = @Category1Code
Insert Into contacts
(
Category1Code ,
Category2Code ,
FirstName,
LastName
)
values
(
@Category1Code ,
@Category2Code ,
@FirstName,
@LastName
)
update contacts set
Category1Code= @CategoryName1,Category2Code= @CategoryName2 where Category1Code = @Category1Code and Category2Code = @Category2Code
end
exec sp_contacts 'C1018', 'C2001', 'ABC','XYZ'
i hope it helps.