What's wrong with my sp?

Here the            ,[CompletedImpForm] and [DateOfFirstVisit are bit type.  I'm getting the following errors but @studyId is a int paramenter while in the table it is a PK int type.  How can I fix this?  Thank you.
Msg 102, Level 15, State 1, Procedure CreateNewAccount, Line 29
Incorrect syntax near ')'.
Msg 137, Level 15, State 2, Line 7
Must declare the scalar variable "@studyId".
Msg 137, Level 15, State 2, Line 9
Must declare the scalar variable "@studyId".
Msg 137, Level 15, State 2, Line 8
Must declare the scalar variable "@studyId".
Msg 102, Level 15, State 1, Line 5
Incorrect syntax near 'END'.
INSERT INTO [AdaptSurvey].[dbo].[Patients]
           ([StudyId]
           ,[CompletedImpForm]
           ,[DoctorId]
           ,[DateOfFirstVisit]
           ,[Active])
     VALUES
           (@studyId
           ,0
           ,@doctorId
           ,@officeDate
           ,1)
GO

Open in new window

lapuccaAsked:
Who is Participating?
 
Pratima PharandeConnect With a Mentor Commented:
try this is it working

CREATE PROCEDURE usp_CreateNewAccount
      -- Add the parameters for the stored procedure here
(      @studyId int, @doctorId int, @officeDate DateTime, @numStepsGoal int,
      @dietGoalOptionId int, @targetNumber int, @aPExerciseOptionsId int, @otherExercise nvarchar(300)
      
)
AS
BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;

-- Insert into Patient table
INSERT INTO [AdaptSurvey].[dbo].[Patients]
           ([StudyId]
           ,[CompletedImpForm]
           ,[DoctorId]
           ,[DateOfFirstVisit]
           ,[Active])
     VALUES
           (@studyId
           ,0
           ,@doctorId
           ,@officeDate
           ,1)
GO
end
0
 
Pratima PharandeCommented:
As per the synatx Inser into syntax looking ok

but erro is
Incorrect syntax near 'END'

So can you share whole procedure ? might be you havn't start the end the bign properly .
Where your have used 'End'

0
 
Pratima PharandeCommented:
Must declare the scalar variable "@studyId".

where you ahve declared @studyId ? is it passed as parameter to SP?
then check the syntax near that
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
lapuccaAuthor Commented:
Hi, attached is my code.  thank you
@studyId is declare as a paramenter to the sp
CreateAccount.sql
0
 
Pratima PharandeCommented:
You missee the paranthesis

try like this

CREATE PROCEDURE usp_CreateNewAccount
      -- Add the parameters for the stored procedure here
(      @studyId int, @doctorId int, @officeDate DateTime, @numStepsGoal int,
      @dietGoalOptionId int, @targetNumber int, @aPExerciseOptionsId int, @otherExercise nvarchar(300)
      
)
AS
0
 
lapuccaAuthor Commented:
duh.. but I added the parenthesis and still got the errors
CREATE PROCEDURE usp_CreateNewAccount
      -- Add the parameters for the stored procedure here
      (@studyId int, @doctorId int, @officeDate DateTime, @numStepsGoal int,
      @dietGoalOptionId int, @targetNumber int, @aPExerciseOptionsId int, @otherExercise nvarchar(300))
      
AS

-----------------------
Msg 102, Level 15, State 1, Procedure usp_CreateNewAccount, Line 29
Incorrect syntax near ')'.
Msg 137, Level 15, State 2, Line 7
Must declare the scalar variable "@studyId".
Msg 137, Level 15, State 2, Line 9
Must declare the scalar variable "@studyId".
Msg 137, Level 15, State 2, Line 8
Must declare the scalar variable "@studyId".
Msg 102, Level 15, State 1, Line 5
Incorrect syntax near 'END'.
0
 
lapuccaAuthor Commented:
I copy your whole code and replace the sp with just that and still got the following error
Msg 102, Level 15, State 1, Procedure usp_CreateNewAccount, Line 26
Incorrect syntax near ')'.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'end'.
0
 
lapuccaAuthor Commented:
I remove all teh "GO"between begin and end of my sp and all the sytax error went away.  Thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.