Solved

Syntax error in error when parsing insert stored procedure

Posted on 2011-03-14
5
296 Views
Last Modified: 2012-05-11
Hello,
I am getting a syntax error on the last line at Distribution Amount in the attached stored procedure I am trying to write.  What am I doing wrong.  I am running SQL Server 2005

The exact error is
Msg 102, Level 15, State 1, Procedure spDistributionTableSupportTeamInsert, Line 14
Incorrect syntax near 'DistributionAmt'.

CREATE PROCEDURE spDistributionTableSupportTeamInsert
@TASKORDER  nvarchar(50)
AS
INSERT INTO Distribution
(TaskOrder,Name, LName, OBS, Department, [Function], InitialPostedDate, LastPostedDate, 
 EligibilityStatus, [Description], Contribution, DistributionAmt)

SELECT   @TASKORDER  , [Name], [LName], [OBS], [Department], [Function], Min([MinOfInitialPostedDate]), 
		 Max([MaxOfLastPostedDate]), [EligibilityStatus], [Description],  [Contribution], 
		 [DistributionAmt] FROM vwRolledUpSupportTeam WHERE [TaskOrder] <> @TASKORDER
		 AND [Name] NOT IN (SELECT [Name] FROM vwShareAllocation WHERE [TaskOrder] = @TASKORDER
         GROUP BY @TASKORDER , [Name], [LName], [OBS], [Department], [Function], [EligibilityStatus], 
         [Description],  [Contribution], [DistributionAmt]

Open in new window

0
Comment
Question by:chtullu135
5 Comments
 
LVL 2

Accepted Solution

by:
enkor earned 125 total points
ID: 35130287
try to put  [DistributionAmt] into select clause
SELECT   @TASKORDER  , [DistributionAmt], [Name], [LName], [OBS], [Department], [Function], Min([MinOfInitialPostedDate]), 
		 Max([MaxOfLastPostedDate]), [EligibilityStatus], [Description],  [Contribution], 
		 [DistributionAmt] FROM vwRolledUpSupportTeam WHERE [TaskOrder] <> @TASKORDER
		 AND [Name] NOT IN (SELECT [Name] FROM vwShareAllocation WHERE [TaskOrder] = @TASKORDER
         GROUP BY @TASKORDER , [Name], [LName], [OBS], [Department], [Function], [EligibilityStatus], 
         [Description],  [Contribution], [DistributionAmt]

Open in new window

0
 
LVL 13

Assisted Solution

by:devlab2012
devlab2012 earned 250 total points
ID: 35130330
at the end put ")".
0
 
LVL 32

Assisted Solution

by:Ephraim Wangoya
Ephraim Wangoya earned 125 total points
ID: 35130335
You don't have a closing bracket
You have to decide where it goes
CREATE PROCEDURE spDistributionTableSupportTeamInsert
@TASKORDER  nvarchar(50)
AS
INSERT INTO Distribution
(TaskOrder,Name, LName, OBS, Department, [Function], InitialPostedDate, LastPostedDate, 
 EligibilityStatus, [Description], Contribution, DistributionAmt)

SELECT   @TASKORDER  , [Name], [LName], [OBS], [Department], [Function], Min([MinOfInitialPostedDate]), 
		 Max([MaxOfLastPostedDate]), [EligibilityStatus], [Description],  [Contribution], 
		 [DistributionAmt] 
 FROM vwRolledUpSupportTeam 
 WHERE [TaskOrder] <> @TASKORDER
 AND [Name] NOT IN (SELECT [Name] 
                    FROM vwShareAllocation WHERE [TaskOrder] = @TASKORDER
                    GROUP BY @TASKORDER, [Name], [LName], [OBS], [Department], [Function], [EligibilityStatus], 
         [Description],  [Contribution], [DistributionAmt])

Open in new window

0
 
LVL 13

Assisted Solution

by:devlab2012
devlab2012 earned 250 total points
ID: 35130342
you have a start "(" in the line:
[Name] NOT IN (SELECT [Name] FROM vwShareAllocation WHERE [TaskOrder] = @TASKORDER

but there is not a corresponding ending parathesis ")"
0
 

Author Closing Comment

by:chtullu135
ID: 35131087
Thanks everyone,  I didn't get enough sleep last night.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Show RTF format in an SSRS report 3 37
online  environment for testing sql queries 5 29
Return Rows as per Quantity of Columns Value In SQL 6 26
SQL Syntax 6 36
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question