469,360 Members | 2,286 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,360 developers. It's quick & easy.

IF Statement Error

1
I'm creating a stored procedure that inserts fields into a table, then after the insert, it updates a field in the current tabled based on the variable. It's simple enough, but it doesnt work. There is a problem in my script somewhere. can you have a look and let me know where i messed up. Thanks

create procedure proc_TI_insert_student
@FirstName varchar(50),
@LastName varchar(50),
@Title varchar(50),
@Facility varchar(50),
@address varchar(50),
@city varchar(50),
@state varchar(50),
@zip int,
@phone1 varchar(50),
@phone2 varchar(50),
@fax varchar(50),
@email varchar(50),
@internal bit,
@empID int

as

set nocount on

insert into Student
(FirstName, LastName, Title, Facility, Address, City, State, Zip, Phone1, Phone2, Fax, email, date, internal)
Values
(@FirstName, @LastName, @Title, @Facility, @address, @city, @state, @zip, @phone1, @phone2, @fax, @email, getdate(), @internal)

IF @internal = 0
UPDATE Student
SET StudentID = @empID
WHERE ID = scope_identity()
END IF

IF @internal = 1
UPDATE Student
SET StudentID = (select cast('100000' as int)+ cast(scope_identity() as int))
WHERE ID = scope_identity()
END IF
Aug 16 '07 #1
1 936
SQL doesn't use "End IF"

Instead put BEGIN and END statements around your IF blocks.
Aug 16 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Jay | last post: by
4 posts views Thread by James E Koehler | last post: by
1 post views Thread by amitbadgi | last post: by
13 posts views Thread by eman1000 | last post: by
8 posts views Thread by Guybrush Threepwood | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.