Debugging apparent syntax error on Create Stored Procedure Statement

Something is wrong with my syntax in the create stored procedure function in the code below.

It keeps giving the following error on the 28th Line which says:       select COUNT(*)

Can anyone point out why?


USE [TRT]
GO

/****** Object:  StoredProcedure [dbo].[usp_SurveyBNBPopulationSize]    Script Date: 04/04/2010 13:22:27 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO


CREATE PROCEDURE [dbo].[usp_SurveyBNBPopulationSize](
	@StartDate	datetime,
	@Debug		bit	=null)
AS

BEGIN

	set nocount on

	declare	@ReturnValue	int

	select	@ReturnValue	=1,
			@Debug			=isnull(@Debug,0)
		
	begin
	select COUNT(*)
	from Orders o (nolock)
	join Customers c (nolock) on c.Customer_ID=o.Order_ID
	where DateDiff(day, o.NextBillDate, @StartDate) = 0
	and exists (select 1 from SVYResponses r1 (nolock) where o.Order_ID=r1.Order_ID and GETDATE() < (DATEADD(DD,30,r1.Datesubmitted)))
	and (select COUNT(*) from SVYResponses r2 (nolock) where o.Order_ID=r2.Order_ID) >= 5
	and not exists (select 1 from Prefs p (nolock) where o.Order_ID=p.Order_ID and p.Active=1 and SVYF_ID=4)
	and c.MemberTypeCode in (1,3)
	--option (maxdop 1)

	if @Debug=1	print convert(char(40),'BNB Population Size Estimate') + convert(char(10),@ReturnValue) )
	end
	
return	@ReturnValue
END

GO

Open in new window

onaled777Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chapmandewCommented:

GO

/****** Object:  StoredProcedure [dbo].[usp_SurveyBNBPopulationSize]    Script Date: 04/04/2010 13:22:27 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO


CREATE PROCEDURE [dbo].[usp_SurveyBNBPopulationSize](
        @StartDate      datetime,
        @Debug          bit     =null)
AS

BEGIN

        set nocount on

        declare @ReturnValue    int

        select  @ReturnValue    =1,
                        @Debug                  =isnull(@Debug,0)
               
        begin
                  select COUNT(*)
                  from Orders o (nolock)
                  join Customers c (nolock) on c.Customer_ID=o.Order_ID
                  where DateDiff(day, o.NextBillDate, @StartDate) = 0
                  and exists (select 1 from SVYResponses r1 (nolock) where o.Order_ID=r1.Order_ID and GETDATE() < (DATEADD(DD,30,r1.Datesubmitted)))
                  and (select COUNT(*) from SVYResponses r2 (nolock) where o.Order_ID=r2.Order_ID) >= 5
                  and not exists (select 1 from Prefs p (nolock) where o.Order_ID=p.Order_ID and p.Active=1 and SVYF_ID=4)
                  and c.MemberTypeCode in (1,3)
                  --option (maxdop 1)

                  if @Debug=1    
                  print convert(char(40),'BNB Population Size Estimate') + convert(char(10),@ReturnValue)
        end
       
return  @ReturnValue
END

GO
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Anthony PerkinsCommented:
>>Can anyone point out why?<<
Did you not see the extra paranthesis underlined in red?
0
onaled777Author Commented:
Thanks chapmandew that worked perfectly.

No acperkins I definitely did not and still do not see any area of the script in red.
0
Anthony PerkinsCommented:
Fair enough.  You must not be using intellisense.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.