Solved

stored  procedure insert

Posted on 2004-09-02
3
285 Views
Last Modified: 2010-04-17
can we use two insert statements in one stored procedure. if so what is the syntax.

thanks

sandeep
0
Comment
Question by:sandeep437
3 Comments
 
LVL 3

Accepted Solution

by:
swarnajyothirmayi123 earned 50 total points
ID: 11968763
Sure you can how many ever statements you want in a stored procedure.

CREATE PROCEDURE sp_add_department
            @Department_Name Nvarchar(50),
            @Department_Desc NVarchar(500),
            @Created_By integer,
            @active integer,
            @Message varchar(100) OUT
AS
Declare @RowCount as Integer
Declare @RowCount1 as Integer
Select @RowCount=count(*) from department where department_name=@Department_Name;

      if(@RowCount>0)
      Begin
            set @Message= 'The Department already exists. Please enter a different departmentname'
            return;
      End

      if(@RowCount=0)
      Begin
            insert into Department(Department_Name,Department_Desc,Created_By,active) values(@Department_Name,@Department_Desc,@Created_By,@active);
insert into table2(a,b,c) values('a','b','c');
insert into table3(a,b,c) values('a','b','c');
insert into table2(a,b,c) values('a','b','c');
      End
GO


I am just posting a sample code. You can infact add any sql statement in the stored procedure.
If you want further information you can contact me.

Swarna
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
When i run adoquery my application freezes 26 178
index Out OF Range Exception error 4 68
Advice in Xamarin 21 96
Select specific duplicate row based on specific criteria 4 55
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question