I have an insert statement where I need to pull data from two tables and I want to insert values. Here is the code that I have so far. I am very new to sql and sql server 2005.
INSERT INTO dbo.risk_Violations(ID, ViolationCode, AccountNo, CellID, ContractLimit, PositionTotal, EODFeedDate, ViolationDate, NotificationFlag)
SELECT (@acctNum + 'CL'), 'CL', @acctNum, @manager, @contractLmt, t.totContracts, n.EODFeedDate, getdate(), 'Y'
FROM dbo.new_Positions n
INNER JOIN @TmpTrader_Tot t
ON n.CellID = @manager
Hopefully you can see what I am trying to do. Is there a better way to do this? When I run the sp I get this error message:
Violation of PRIMARY KEY constraint 'PK_risk_Violations'. Cannot insert duplicate key in object 'dbo.risk_Violations'.
The statement has been terminated.
But the table is empty so I don't understand why it says that it is a duplicate key?
Thank you for all your help.