Solved

stored  procedure insert

Posted on 2004-09-02
3
282 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
object oriented javascript web form 8 100
Magic Software info 18 124
wordappend challenge 8 143
Tembedded WB animatid gifs not animated on some pcs 2 71
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.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

932 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now