• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 440
  • Last Modified:

Declaring @Local_Variable and @Parameters in Stored Procedure

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.
2 Solutions
Chris LuttrellSenior Database ArchitectCommented:
Yes, like this:

CREATE Procedure myProc (@Parm1 INT, @Parm2 VARCHAR(20))
    Declare @Loc_Var int; -- etc
    --Your other code here using them something like this
    Set @Loc_Var = @Parm1;
A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

RadhaKrishnaKiJayaAuthor Commented:
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?)
Anthony PerkinsCommented:
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#.
RadhaKrishnaKiJayaAuthor Commented:
acperkins, Thank you for your advice.
RadhaKrishnaKiJayaAuthor Commented:
Thank you guys for your help.  I really appricate it.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now