dcsimg
Results 1 to 5 of 5

Thread: Need help with variables

  1. #1
    Join Date
    Jun 2011
    Posts
    5

    Need help with variables

    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!

  2. #2
    Join Date
    Sep 2002
    Posts
    5,938
    Create stored procedure for that, you can pass variable to sp.

  3. #3
    Join Date
    Jun 2011
    Posts
    5
    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?

  4. #4
    Join Date
    Sep 2002
    Posts
    5,938
    Yes you can, but you have to declare variable for each run. Besides, rdbms caches sp execution plan so better performance.

  5. #5
    Join Date
    Jun 2011
    Posts
    5
    This query will be run ad hoc so I'm ok with setting the region number variable with each run.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •