# Miscellaneous > Structured Query Language (SQL) >  Need help with variables

## jlp44

In the database, different regions are identified by a region number.  I have a long, complicated query and what I'd like to do is use a variable for the region number.  That way if I want to run the query for a different region, I can change the region number in just one place instead of 5 places scattered throughout the query.  

I've tried a few things based on examples I found online but I just can't get it to work for some reason.  Help!

----------


## rmiao

Create stored procedure for that, you can pass variable to sp.

----------


## jlp44

I'm a beginner, so I'm sorry if this is a dumb question... but why do I need a stored procedure?  isn't there a way to just declare a variable and set its value at the beginning of my query?

----------


## rmiao

Yes you can, but you have to declare variable for each run. Besides, rdbms caches sp execution plan so better performance.

----------


## jlp44

This query will be run ad hoc so I'm ok with setting the region number variable with each run.

----------

