Syntax problem constructing SQL statement for Stored Procedure

Greetings all

I am trying to create a stored proc (see snippet)  that will update two tables. The proc will be call from an SqlDataAdapter.

The data consists of Pupil data ("master record") and Registration data.

My error:  Msg 102, Level 15, State 1, Procedure Registration_Insert, Line 40
Incorrect syntax near '@iPupil_No'.  --> Line 40 = @iPupil_No = select P_No from Pupil where (P_ID_No = @P_ID_No);


Any ideas??

PUPIL:
  P_No			int IDENTITY(1,1) not null,
  P_First_Name		varchar(15) not null,
  P_Second_Name		varchar(15),
  P_Surname		varchar(30) not null,
  P_ID_No		varchar(13),
  .........................
  ................
 
ANNUAL_CARD:
  AC_No			int IDENTITY(1,1) not null,
  AC_Pupil_No		int not null,
  AC_Year		smallint not null,
  AC_Grade		char(3) not null,
  AC_Subsidised		bit not null default(0),
  AC_Payment_Type	char(1) not null,
  .................
  ..................
 
 
THE SQL:
 
CREATE procedure [dbo].[Registration_Insert]
	@P_First_Name varchar(15),
	@P_Surname varchar(30),
	@Pupil_Status varchar(15),
	@P_ID_No varchar(13),
	@P_Father_Name varchar(15),
	@P_Father_Surname varchar(30),
	@P_Father_Title tinyint,
	@P_Father_ID_No varchar(13),
	@P_Mother_Name varchar(15),
	@P_Mother_Surname varchar(30),
	@P_Mother_Title tinyint,
	@P_Mother_ID_No varchar(13),
	@P_Custody_Name varchar(15),
	@P_Custody_Surname varchar(30),
	@P_Custody_Status char(1),
	@P_LastUpdated_Date smalldatetime,
	@AC_Pupil_No int,
	@AC_Year smallint,
	@AC_Grade char(3),
	@AC_Payment_Type char(1),
	@AC_Num_Payms_Due bit,
	@AC_Last_Paym_No tinyint,
	@AC_Last_Paym_Date smalldatetime,
	@AC_Reg_Completed bit,
	@AC_All_Doc_Comp bit,
	@AC_Signed_Accept_Resp bit,
	@AC_Override_Incomplete bit,
	@AC_LastUpdated_Date smalldatetime
AS
  DECLARE @iPupil_No int 
 
insert into Pupils(P_First_Name, P_Surname, Pupil_Status, P_ID_No, P_Father_Name, P_Father_Surname, 
      P_Father_Title, P_Father_ID_No, P_Mother_Name, P_Mother_Surname, P_Mother_Title, P_Mother_ID_No,
      P_Custody_Name, P_Custody_Surname, P_Custody_Status, P_LastUpdated_Date)
values(@P_First_Name, @P_Surname, @Pupil_Status, @P_ID_No, @P_Father_Name, @P_Father_Surname, 
       @P_Father_Title, @P_Father_ID_No, @P_Mother_Name, @P_Mother_Surname, @P_Mother_Title, @P_Mother_ID_No,
       @P_Custody_Name, @P_Custody_Surname, @P_Custody_Status, @P_LastUpdated_Date);
    
@iPupil_No = select P_No from Pupil where (P_ID_No = @P_ID_No);
 
insert into Annual_Card(AC_Pupil_No, AC_Year, AC_Grade, AC_Payment_Type, AC_Num_Payms_Due, AC_Last_Paym_No,
	AC_Last_Paym_Date, AC_Reg_Completed, AC_All_Doc_Comp, AC_Signed_Accept_Resp, AC_Override_Incomplete,
	AC_LastUpdated_Date)
values(@iPupil_No, @AC_Year, @AC_Grade, @AC_Payment_Type, @AC_Num_Payms_Due, @AC_Last_Paym_No, @AC_Last_Paym_Date,
	@AC_Reg_Completed, @AC_All_Doc_Comp, @AC_Signed_Accept_Resp, @AC_Override_Incomplete, @AC_LastUpdated_Date);

Open in new window

allanmarkAsked:
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.

Aneesh RetnakaranDatabase AdministratorCommented:

CREATE procedure [dbo].[Registration_Insert]
        @P_First_Name varchar(15),
        @P_Surname varchar(30),
        @Pupil_Status varchar(15),
        @P_ID_No varchar(13),
        @P_Father_Name varchar(15),
        @P_Father_Surname varchar(30),
        @P_Father_Title tinyint,
        @P_Father_ID_No varchar(13),
        @P_Mother_Name varchar(15),
        @P_Mother_Surname varchar(30),
        @P_Mother_Title tinyint,
        @P_Mother_ID_No varchar(13),
        @P_Custody_Name varchar(15),
        @P_Custody_Surname varchar(30),
        @P_Custody_Status char(1),
        @P_LastUpdated_Date smalldatetime,
        @AC_Pupil_No int,
        @AC_Year smallint,
        @AC_Grade char(3),
        @AC_Payment_Type char(1),
        @AC_Num_Payms_Due bit,
        @AC_Last_Paym_No tinyint,
        @AC_Last_Paym_Date smalldatetime,
        @AC_Reg_Completed bit,
        @AC_All_Doc_Comp bit,
        @AC_Signed_Accept_Resp bit,
        @AC_Override_Incomplete bit,
        @AC_LastUpdated_Date smalldatetime
AS
  DECLARE @iPupil_No int 
 
insert into Pupils(P_First_Name, P_Surname, Pupil_Status, P_ID_No, P_Father_Name, P_Father_Surname, 
      P_Father_Title, P_Father_ID_No, P_Mother_Name, P_Mother_Surname, P_Mother_Title, P_Mother_ID_No,
      P_Custody_Name, P_Custody_Surname, P_Custody_Status, P_LastUpdated_Date)
values(@P_First_Name, @P_Surname, @Pupil_Status, @P_ID_No, @P_Father_Name, @P_Father_Surname, 
       @P_Father_Title, @P_Father_ID_No, @P_Mother_Name, @P_Mother_Surname, @P_Mother_Title, @P_Mother_ID_No,
       @P_Custody_Name, @P_Custody_Surname, @P_Custody_Status, @P_LastUpdated_Date);
    
SELECT @iPupil_No = SCOPE_IDENTITY()
 
insert into Annual_Card(AC_Pupil_No, AC_Year, AC_Grade, AC_Payment_Type, AC_Num_Payms_Due, AC_Last_Paym_No,
        AC_Last_Paym_Date, AC_Reg_Completed, AC_All_Doc_Comp, AC_Signed_Accept_Resp, AC_Override_Incomplete,
        AC_LastUpdated_Date)
values(@iPupil_No, @AC_Year, @AC_Grade, @AC_Payment_Type, @AC_Num_Payms_Due, @AC_Last_Paym_No, @AC_Last_Paym_Date,
        @AC_Reg_Completed, @AC_All_Doc_Comp, @AC_Signed_Accept_Resp, @AC_Override_Incomplete, @AC_LastUpdated_Date);

Open in new window

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
allanmarkAuthor Commented:
Thanks!

Away from PC at moment - will have a go on Saturday morning.
0
allanmarkAuthor Commented:
Perfect!!  Thanks very much!!
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 2005

From novice to tech pro — start learning today.