Jesi523 0 Junior Poster in Training

I have a stored procedure where I need to insert from some other tables when those items do not exist in the original table. Here’s the stored procedure that I wrote.

ALTER PROCEDURE [dbo].[sp_CreateRequestedItems]
	
AS
BEGIN
INSERT INTO dbo.RequestItems
([request], [applicationProfile])

--select from requests and profiles table into requestitems table based on dept and job codes
Select Requests.rAuid,
Profiles.applicationProfile
From Requests 
left join Profiles
on Requests.departmentCode = Profiles.deptCode and Requests.jobCode = Profiles.jobCode
WHERE NOT EXISTS (SELECT * from RequestItems  where request <> rAuid)
END

Here’s the error I am getting:
Cannot insert the value NULL into column 'applicationProfile', table 'UserAccess.dbo.RequestItems'; column does not allow nulls. INSERT fails.

The 2 columns I am trying to insert are foreign keys and they cannot be null true, but I don’t know what I am doing wrong. Please help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.