Solved

Declaring @Local_Variable and @Parameters in Stored Procedure

Posted on 2013-01-08
7
430 Views
Last Modified: 2013-01-09
Hi Experts,
Can we declare Local Variables and Parameters in a Stored Procedure in SQL?  I have couple of parameters to pass from the program, at the same time I need to declare couple of Local Variables to do some calaculations in the SP.  Please let me know.  Thank you very much in advance.
0
Comment
Question by:RadhaKrishnaKiJaya
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 2

Expert Comment

by:harshada_sonawane
ID: 38757819
yes
0
 
LVL 26

Accepted Solution

by:
Chris Luttrell earned 250 total points
ID: 38757820
Yes, like this:

CREATE Procedure myProc (@Parm1 INT, @Parm2 VARCHAR(20))
AS
Begin
    Declare @Loc_Var int; -- etc
    --Your other code here using them something like this
    Set @Loc_Var = @Parm1;
End
0
 
LVL 12

Assisted Solution

by:Saurabh Bhadauria
Saurabh Bhadauria earned 250 total points
ID: 38757884
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:RadhaKrishnaKiJaya
ID: 38760099
Thank you CGLuttrell.  I did exactly like that.  The problem is, I have 2 parameters passing from program.  Ovbiously I need 2 parameters in the SP.  Till this time I don't have any problem.  When I create the local variables (Declare @Loc_Var int; etc.) my C# program doesn't compile with the error message as below.  But when I remove ethe Declare statement from the SP, it compiles fine.  Any idea, how I can fix this issue?

DataLayer.DataModule' does not contain a definition for 'getXXXStoreProcedure' and no extension method 'getXXXStoreProcedure' accepting a first argument of type 'DataLayer.DataModule' could be found (are you missing a using directive or an assembly reference?)
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 38760331
Your original question has been fully answered, I would suggest if you need help with this followup question that you post the relevant code from your Stored Procedure and from C#.
0
 

Author Comment

by:RadhaKrishnaKiJaya
ID: 38760415
acperkins, Thank you for your advice.
0
 

Author Closing Comment

by:RadhaKrishnaKiJaya
ID: 38760568
Thank you guys for your help.  I really appricate it.
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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

732 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