Solved

Syntax error in error when parsing insert stored procedure

Posted on 2011-03-14
5
291 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:ewangoya
ewangoya 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now