Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Declaring @Local_Variable and @Parameters in Stored Procedure

Posted on 2013-01-08
7
Medium Priority
?
435 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 27

Accepted Solution

by:
Chris Luttrell earned 1000 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 1000 total points
ID: 38757884
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
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 INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

597 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