Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4014862
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:32:54+00:00 2026-05-20T09:32:54+00:00

Is it possible to change a query in Reporting Services based on a parameter?

  • 0

Is it possible to change a query in Reporting Services based on a parameter?

I’d like to be able to change table names within the query from tableName to tableName2 (for example) on the fly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T09:32:55+00:00Added an answer on May 20, 2026 at 9:32 am

    There are two ways you could do it:

    1. Write multiple queries (one for each table), then switch among then based upon the parameter value
    2. Use dynamic SQL

    For 1, you’d do something like this:

    if @param = 'value'
        select Col1, Col2 from Table1
    else
        select Col1, Col2 from Table2
    

    For 2, you’d do something like this:

    declare @sql nvarchar(4000)
    
    select @sql = 'select Col1, Col2 from' + (case when @param = 'value' then 'Table1' else 'Table2' end)
    
    sp_executesql @sql
    

    WARNING: Be very careful of option 2. If option 1 is feasible, then it is the safer option, as dynamically constructing SQL based upon user-supplied values is always a dangerous affair. While this particular example doesn’t use the parameter directly in the SQL, it would be very easy to write something that did, and thus very easy to find a way to exploit it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to change order of records/groups in a result-set from a query
Is it possible to programatically change the query URL within PHP? I know I
Is it possible to change the frame title when using \againframe from the Beamer
Is it possible to change the auto-increment offset on a pre-existing table with JavaDB?
Is it possible to change current directory from a script? I want to create
Wondering if it's possible to change a value returned from a queryset before sending
I'm trying to work out whether it is possible to change the icon based
Possible Duplicate: Query about Html <input type=password> tag…? I want change the character displayed
I was hoping to change one of the variables of a query, from inside
Is it possible to perform a JOIN sub query against a Common Table Expression?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.