Congratulations to all monthly winners of May 2013 !!! They have won INR 2900 cash and INR 27497 worth prize.
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 26467 |  Welcome, Guest!   Register  Login
 Home > Forums > Others > procedures with example for insertion,selection ...
Malar

procedures with example for insertion,selection

Replies: 3 | Posted by: Malar on 7/9/2012 | Category: Others Forums | Views: 244 | Status: [Member] | Points: 10  


how to write procedures with example for insertion,selection


Reply | Reply with attachment | Alert Moderator

 Responses below this adGet hundreds of .NET Tips and Tricks videos

 Replies

Premalatha
Premalatha  
Posted on: 7/9/2012 12:12:00 PM
Level: Starter | Status: [Member] | Points: 25

/*
(
@parameter1 datatype = default value,
@parameter2 datatype OUTPUT
)
*/
AS
/* Place your Query here */
RETURN

Example 1:
Create PROCEDURE dbo.GetAllEmployees
As

Select * from Employee

Execution query :

exec GetAllEmployees

Example 2:
ALTER PROCEDURE dbo.GetEmployee
@empid int
As

Select * from Employee where Employee.EmployeeID=@empid

Execution Query :

exec dbo.GetEmployee 1

Example 3:

Create PROCEDURE dbo.UpdateEmpNationalID

(
@empid int
,@newcontactid int
,@oldcontactno int OUTPUT
)

AS

Select @oldcontactno=[ContactID]
FROM [dbo].[Employee] where [Employee].EmployeeID=@empid

if(@oldcontactno=@newcontactid)
begin

RETURN 0

end

else
begin

update Employee set ContactID=@newcontactid where Employee.EmployeeID=@empid

return 1
end

Execution Query:
Declare @oldcontactno int
Declare @returnvalue int
exec @returnvalue=UpdateEmpNationalID 1,123,@oldcontactno output

Select @oldcontactno 'Old Contact'
Select @returnvalue 'Returned value'

Premalatha
Software Engineer

Malar, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Premalatha
Premalatha  
Posted on: 7/9/2012 12:13:41 PM
Level: Starter | Status: [Member] | Points: 25

CREATE PROCEDURE rsp_authuser
@uname as varchar(20),
@pword as varchar(21) OUTPUT,
@profile as varchar(21)OUTPUT
AS
SELECT @pword = password,@profile = profile FROM authentication WHERE
username = @uname AND active = 'yes'
GO


This stored procedure can then be executed from a *.aut file as follows:

SQL= {call rsp_authuser (%username!i, %password!o, %profile!o)}
[results]
; No entries should be specified in results, everything but the header should be
commented out.

Premalatha
Software Engineer

Malar, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Premalatha
Premalatha  
Posted on: 7/9/2012 12:14:46 PM
Level: Starter | Status: [Member] | Points: 25

http://www.simple-talk.com/sql/learn-sql-server/working-with-the-insert-statement-in-sql-server/

Premalatha
Software Engineer

Malar, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Reply - Please login to reply


Click here to login & reply

Found interesting? Add this to:


 Latest Posts

Write New Post | More ...

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 6/18/2013 3:30:13 AM