473,657 Members | 2,661 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to merge two stored procedures

14 New Member
I have two stored procedures one for INSERT and second for Update and I'd like to merge them in one so could you please tell me which satement should I use for that ?

Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE Tools
  2. (@CategoryID_1 int,
  3.  @CategoryName_2 nvarchar(100),
  4.  @Description_3 ntext)
  5.  
  6. AS INSERT INTO Categories 
  7.  (CategoryID,
  8.  CategoryName,
  9.  Description) 
  10.  
  11. VALUES 
  12. (@CategoryID_1,
  13.  @CategoryName_2,
  14.  @Description_3)
  15. go
  16.  
  17. CREATE PROCEDURE Tools1
  18.  
  19.      (@CategoryID_1     [int],
  20.  @CategoryID_2  [int],
  21.  @CategoryName_3    [nvarchar](50),
  22.  @Description_4     [ntext],
  23.  
  24. AS UPDATE [Teachdb].[dbo].[Categories] 
  25.  
  26. SET  [CategoryID]    = @CategoryID_2,
  27.  [CategoryName]  = @CategoryName_3,
  28.  [Description]   = @Description_4,
  29.  
  30. WHERE 
  31. ( [CategoryID]   = @CategoryID_1)
  32. go
Apr 1 '13 #1
3 3183
r035198x
13,262 MVP
You can use EXEC to call a stored procedure from another.
Apr 1 '13 #2
gelezniyden
14 New Member
I'd like to create one for all Update and Insert
Apr 1 '13 #3
gelezniyden
14 New Member
Resolved issue following way:

Expand|Select|Wrap|Line Numbers
  1.  
  2. CREATE PROCEDURE Tools
  3. (
  4.     @Mode nvarchar(100), 
  5.     @CategoryID int,
  6.     @CategoryName nvarchar(100),
  7.     @Description ntext
  8. )
  9.  
  10. AS 
  11. BEGIN 
  12.     IF @Mode = 'INSERT'
  13.     BEGIN
  14.         INSERT INTO Categories (CategoryID, CategoryName, Description) 
  15.         VALUES (@CategoryID, @CategoryName, @Description)
  16.     END
  17.     ELSE IF @Mode = 'UPDATE'
  18.     BEGIN
  19.         UPDATE Categories
  20.             SET  CategoryID   = @CategoryID,
  21.                 CategoryName  = @CategoryName,
  22.                 Description   = @Description
  23.         WHERE ([CategoryID]   = @CategoryID)
  24.     END
  25. END
  26. go
  27.  
Apr 1 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
3508
by: M Wells | last post by:
Hi All, I'm wondering if anyone can tell me if it's possible to search for stored procedures by their contents? I tend to leave very descriptive notes in stored procedures and they're beginning to build up in number, so I'm wondering if it's possible to search in Query Analyzer for stored procedures that contain certain words / phrases etc.
17
2195
by: serge | last post by:
How can i delete all user stored procedures and all table triggers very fast in a single database? Thank you
11
10744
by: jrefactors | last post by:
I want to know the differences between SQL Server 2000 stored procedures and oracle stored procedures? Do they have different syntax? The concept should be the same that the stored procedures execute in the database server with better performance? Please advise good references for Oracle stored procedures also. thanks!!
2
2813
by: scott | last post by:
Hi, Just wondering what sort of problems and advantages people have found using stored procedures. I have an app developed in VB6 & VB.NET and our developers are starting to re-write some of the code in stored procedures (im advocating encryption of them). When deploying an application however stored procedure seem to add another level of complexity to installation. In future we also plan to have an basic ASP app with some of the...
0
1335
by: Tim Bolla | last post by:
I have created ~30 stored procedures that I need to have running on a database in order to use the application that I have developed. I am looking for a solution so that these stored procedures can be imported by other people with the least amount of work. I have been exporting the stored procedures from the DB2 Development Center to a zip file and then using the Project Deployment tool to import the stored procedures. While in the...
2
9218
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered problems doing this. I wanted to implemented a generic "Helper" class like this: /** * Helper
5
3470
by: Tim Marshall | last post by:
I was following the thread "Re: Access Treeview - Is it Safe Yet?" with interest and on reading the post describing Lauren Quantrell's SmartTree, I've run into something I don't understand: Stored Procedures. I thought stored pricedures were an Oracle/MS SQL Server thing and don't know how they work with Access Jet. I've looked at some of the help on stored procedures in A2003, but really don't understand what's going on. Can someone...
45
3390
by: John | last post by:
Hi When developing vb.bet winform apps bound to sql server datasource, is it preferable to use SELECTs or stored procedure to read and write data from/to SQL Server? Why? Thanks Regards
28
72456
by: mooreit | last post by:
The purpose for my questions is accessing these technologies from applications. I develop both applications and databases. Working with Microsoft C#.NET and Microsoft SQL Server 2000 Production and 2005 Test Environments. What is the purpose of a view if I can just copy the vode from a view and put it into a stored procedure? Should I be accessing views from stored procedures?
1
7756
by: Quish | last post by:
Hey I am creating a database application that is accessed through a .NET front end. What I want to do is run a SQL script that will create my DB, create my indexes and enforce my constraints (all of which I have done) but I also want to create my stored procedures in the same script also. When I merge all my stored procedures (about 16) into one file and run it in SQL Query Analyser I get multiple errors but the one that is coursing me...
0
8407
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8319
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8837
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8512
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7347
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6175
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.