Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Local Variables in Stored Procedure

Status
Not open for further replies.

VBXL

Programmer
Jul 10, 2001
198
0
0
GB
Hi

Is it possible to have local variables to stored procedure.

I want to create some variables inside the stored procedure that i dont have to call

Cheers

Xplain
 
declare @local_var_name

Be sure to start the var name with an '@' or it won't validate

thanks
Salma
 
sorry forgot the datatye

declare @local_var_name datatype

e.g. declare @temp int
 
Yes it is possible to use local variables.

Have a look at the following topic in BOL:

DECLARE @local_variable (T-SQL)



Rick.
 
Is it possible to have User Defined Types in a stored procedure

i.e

private type Example

a int
b varchar
c int

End Type
 
Not sure if I fully understand your question but the following example is perfectly acceptable.

CREATE PROCEDURE upz_variables
AS
SET NOCOUNT ON

declare @internal_var1 int
declare @internal_var2 varchar(5)
declare @internal_var3 datetime

Set @internal_var1 = 1
Set @internal_var2 = 'Text5'
Set @internal_var3 = (select getdate())



Rick.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top