Saturday, 27 July 2013

Stored Proc's



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

end
else
begin


insert into tbl_Students(Studentid,Firstname,lastname,Email) values (@Studentid,@Firstname,@lastname,@Email)
    set @Studentid = @@IDENTITY;
    end
    end
    go
  
  
>execute InsertValues 5,'XHema','Xlatha','XHemalatha@hotmail.com'



 >SELECT * FROM [Working].[dbo].[tbl_Students]
 >Select @@rowcount

No comments:

Post a Comment