How to create Same Name Stored Procedure with different Logic in Sqlserver.

Hi All, generally when we create multiple stored procedures with the same name we get error (like: sp already exists n all). But if we follow specific syntax then we can create same name sp with different logic. I show you:

alter PROCEDURE testSunil; 1 @id INT
AS
BEGIN
    SELECT ‘First Procedure’
END
GO

alter PROCEDURE testSunil; 2 @id2 INT,@name NVARCHAR(100)
AS
BEGIN
    SELECT ‘Second Procedure’
END
GO

alter PROCEDURE testSunil; 3 @id3 INT,@name NVARCHAR(100),@salary Decimal(18,2)
AS
BEGIN
    SELECT ‘Third Procedure’
END
GO

exec testSunil; 1 ‘1’
exec testSunil; 2 ‘1’,’sunil’
exec testSunil; 3 ‘1’,’sunil’,85000

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s