• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 272
  • Last Modified:

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

0
onaled777
Asked:
onaled777
  • 2
1 Solution
 
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
 
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

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now