Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have created one stored procedure in which i performed insert query below is the code

ALTER PROCEDURE sp1
/*
(
@parameter1 int = 5,
@parameter2 datatype OUTPUT
)
*/
(

@name nvarchar(50),
@age nvarchar(50)
)


AS
/* SET NOCOUNT ON */
insert into customer values(@name,@age)
RETURN




now what i want is that i could perform update and delete and select query in the same stored procedure.....................and in front end when i click on select, insert, update , delete button its respective operation should work taking from one stored procedure.....


how can i achieve this..............
regards,
Posted

SQL
CREATE PROCEDURE ASampleProcedure
(
@id int,
@name varchar(50),
@age int,
@option int
)
AS
BEGIN
if @option = 1
BEGIN
--insert record
insert into customer values (@name, @age)
select 'Record inserted.' as Result
END
else
BEGIN
if @option = 2
BEGIN
--update record
update customer set [Name] = @name, [Age] = @age where ID = @id
select 'Record updated.' as Result
END
else
BEGIN
--deleterecord
delete from customer where ID = @id
select 'Record deleted.' as Result
END
END
END


From your front end pass parameters and option (1,2 or 3) This single procedure will perform all the operations.
 
Share this answer
 
Comments
vinodkumarnie 25-Jan-13 6:24am    
Remember that - you have to pass all parameter from your code behind in each click with respective option value....
yes, you can do it you can pass one more parameter called @Trans_Type varchar type
and the call that parameter in page itself.

ex

SQL
IF @Trans_Type='select'
--select query
else if @trans_type='delete'
--delete query
else if @trans_type='insert'
--insert query


like that you can use it no problem in that
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900