I have a sql database I wrote that has a few tables in it.
First table contains the assigned companies
It has two columns 1 is the username and 1 is the company both are nvarchar(100)
The second table is called assignloans and it contains the usernames with the loan numbers assigned to them.
The third table contains all the loan information I need.
So here is my issue. I am trying to create it so that if I have two usernames both assigned to the same company that when my query runs it puts in the loan numbers and the usernames into the assignloans table.
It is working half way where it is only inserting 1 of the usernames. I know its going ot be something simple but am just beating my head on the wall now.
if not exists(Select d.xrefid,d.company,e.userid from outlookreport.dbo.loanselect d,outlookreport.dbo.assignloans e ,outlookreport.dbo.userassign f where e.xrefid=d.xrefid and f.username = e.userid)
insert into outlookreport.dbo.assignloans(xrefid,userid)
select a.xrefid, b.username
from outlookreport.dbo.loanselect a, outlookreport.dbo.userassign b, outlookreport.dbo.assignloans c
where a.company=b.company and b.username <> c.userid