WORKING
with Stored Proc with Insert /Update:
use Working
go
Create proc InsertValues
(
@Studentid int,
@Firstname nvarchar(50),
@Lastname nvarchar(50),
@Email nvarchar(50)
)
as
begin
if @studentid =0 -- does not allow duplicates values
begin
UPDATE tbl_Students
SET Firstname = @Firstname,
Lastname = @Lastname,
Email = @Email
Where Studentid=@Studentid
Create proc InsertValues
(
@Studentid int,
@Firstname nvarchar(50),
@Lastname nvarchar(50),
@Email nvarchar(50)
)
as
begin
if @studentid =0 -- does not allow duplicates values
begin
UPDATE tbl_Students
SET Firstname = @Firstname,
Lastname = @Lastname,
Email = @Email
Where Studentid=@Studentid
end
else
begin
insert into tbl_Students(Studentid,Firstname,lastname,Email) values (@Studentid,@Firstname,@lastname,@Email)
set @Studentid = @@IDENTITY;
end
end
go
else
begin
insert into tbl_Students(Studentid,Firstname,lastname,Email) values (@Studentid,@Firstname,@lastname,@Email)
set @Studentid = @@IDENTITY;
end
end
go
>SELECT * FROM [Working].[dbo].[tbl_Students]
>Select @@rowcount
No comments:
Post a Comment