Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating a Query on SQL Dashboard

Status
Not open for further replies.

CHMS2013

IS-IT--Management
Jun 5, 2013
5
US
Hello and good morning. I am VERY new to this whole SQL thing.

I am trying to update a monthly sales scorecard in SQL, I have the scorecard insert opened up in SQL, as well as the info that needs to go on it however I am stumped when it comes to updating it.

This is the text on the scorecard right now:

INSERT INTO dbo.ScorecardSalesGoals

(SalesRep,Period,Goal)

VALUES('HMS','2013-4-01',70000.00)

GO



I'm stumped to where I put the sales rep, the month and the amount.
 
This bit

CHMS2013 said:
VALUES('HMS','2013-4-01',70000.00)

Is inserting a record for sales rep "HMS", a period of april 2013 and, 700000 as a goal.

HMS i am guessing is a key reference to the actual name of the sales rep?



----------------------------------------

Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind - Bernard Baruch

Computer Science is no more about computers than astronomy is about telescopes - EW Dijkstra
----------------------------------------
 
Yes, I would assume that the HMS is the sales rep. All of our employees go by a 3 digit code in our system.

For example, I tried:

'TMO','2013-6-01',90000.00

and received an error.
 
It would probably be helpful to know what the error message is.

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
That probably would have helped. Below is the error and I've attached a screenshot if that helps.

Msg 2627, Level 14, State 1, Line 1
Violation of PRIMARY KEY constraint 'PK_ScorecardSalesGoals_1'. Cannot insert duplicate key in object 'dbo.ScorecardSalesGoals'.
The statement has been terminated.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'TMO'.


SQL_ERROR.jpg
 
Here's my guess....

There is a primary key constraint on the ScoreCardSalesGoal table. The primary key for this table is probably SalesRep (but that's just a guess). What this means is that there cannot be any duplicates to the values in that column. You also cannot have a null value in the primary key column.

To know for sure whether the SalesRep column is the primary key, run this in a new query window.

Code:
sp_helpIndex 'ScorecardSalesGoals'

There will be at least one row, if not more. Can you copy/paste the output here?

The code you TRIED to execute is this:

Code:
INSERT INTO dbo.ScorecardSalesGoals
(SalesRep,Period,Goal)
VALUES('HMS','2013-4-01',70000.00)
GO
VALUES('TMP','2013-6-01',25500.00)

There are actually 2 errors that you got. The "Violation of PRIMARY KEY constraint" error came from this part:

Code:
INSERT INTO dbo.ScorecardSalesGoals
(SalesRep,Period,Goal)
VALUES('HMS','2013-4-01',70000.00)

The second error you got was "Incorrect syntax new 'TMO'", which came from here:

Code:
VALUES('TMP','2013-6-01',25500.00)

You see... when you use the GO keyword in SQL Server Management Studio, it's actually a "batch" separator. Meaning... it treats the first part (the part before the GO) as a separate command than the code after the GO.

To insert a new value in to the ScoreCardSalesGoals table, use the following code:

Code:
INSERT INTO dbo.ScorecardSalesGoals
(SalesRep,Period,Goal)
VALUES('TMP','2013-6-01',25500.00)

Does this make sense?

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top