Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2005
»
SQL Server 2005 General Discussion
»
Insert combo in table
Insert combo in table
Rate Topic
Display Mode
Topic Options
Author
Message
ltmnm
ltmnm
Posted Friday, January 11, 2008 9:48 AM
Forum Newbie
Group: General Forum Members
Last Login: Tuesday, April 07, 2009 11:13 AM
Points: 3,
Visits: 61
Hello all,
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.
Post #441871
Jack Corbett
Jack Corbett
Posted Friday, January 11, 2008 9:59 AM
SSChampion
Group: General Forum Members
Last Login: Friday, May 17, 2013 12:22 PM
Points: 10,571,
Visits: 11,871
Remoive the insert statement from your code so you can see the results of your query. You will see that you are getting multiple records returned by your select that contain duplicate key values. If all the data is the same you can use either select distinct or a group by to eliminate the error. If you are getting different results with the same ID then you have a data issue or design issue.
Jack Corbett
Applications Developer
Don't let the good be the enemy of the best. --
Paul Fleming
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #441880
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.