Click here to Skip to main content
15,913,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to create stored procedure with multiple command as select ,insert,update,delete on login table
login table is
SQL
create table Login
(
Emp_name varchar(20),
id varchar(10),
password varchar(10),
Address varchar(20)
);

Please help me how?
Posted
Updated 3-May-12 0:27am
v2
Comments
Rahul Rajat Singh 3-May-12 6:38am    
Do you want to execute all commands in a sequence or on an either or basis(got confused by one of the posted answers)

SQL
create proc proc_name  para_command varchar
as
begin
if para_command="select"
begin
--select operation
end
if para_command="inser"
begin
--inser operation
end
if para_command="update"
begin
--updateoperation
end
if para_command="delete"
begin
--delete operation
end
end


hope this will solve ur problem
 
Share this answer
 
v2
Hi,

try this
SQL
create procedure usp_LoginTable
(
	@intOption int=0 ,/* 1 for insert, 2 for update, 3 for delete*/
	@Emp_name varchar(20)='',
	@id varchar(10)='',
	@password varchar(10)='',
	@Address varchar(20)=''
)
as
begin
IF @intOption=1 --INSERT
	begin	
		insert into [Login](Emp_name,id,[password],[Address])
		values (@Emp_name,@id,@password,@Address)
	end
ELSE IF @intOption=2	---UPDATE
	begin
		update [Login] set Emp_name=@Emp_name,id=@id,[password]=@password,[Address]=@Address
		where 	id=@id
	end
ELSE IF @intOption=3	---DELETE
	begin
		Delete from [Login] where 	id=@id
	end
end

Best Luck
Happy Coding:)
 
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