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 44479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:39:31+00:00 2026-05-10T15:39:31+00:00

I have a report in SSRS 2005 that’s based on a query that’s similar

  • 0

I have a report in SSRS 2005 that’s based on a query that’s similar to this one:

SELECT * FROM MyTable (NOLOCK)  WHERE col1 = 'ABC' AND col2 LIKE '%XYZ%' 

I need to be able to dynamically include the AND part of the WHERE clause in the query based on whether the user has checked a checkbox. Basically, this is a dynamic SQL statement and that’s the problem. I tried several approaches to no avail. Is this possible? Does SSRS 2005 supports dynamic SQL? Thanks!

  • 1 1 Answer
  • 2 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. 2026-05-10T15:39:32+00:00Added an answer on May 10, 2026 at 3:39 pm

    Charles almost had the correct answer.

    It should be:

    SELECT * FROM MyTable (NOLOCK)  WHERE col1 = 'ABC'    AND (@checked = 0 OR col2 LIKE '%XYZ%') 

    This is a classic ‘pattern’ in SQL for conditional predicates. If @checked = 0, then it will return all rows matching the remainder of the predicate (col1 = 'ABC'). SQL Server won’t even process the second half of the OR.

    If @checked = 1 then it will evaluate the second part of the OR and return rows matching col1 = 'ABC' AND col2 LIKE '%XYZ%'

    If you have multiple conditional predicates they can be chained together using this method (while the IF and CASE methods would quickly become unmanageable).

    For example:

    SELECT * FROM MyTable (NOLOCK)  WHERE col1 = 'ABC'     AND (@checked1 = 0 OR col2 LIKE '%XYZ%')     AND (@checked2 = 0 OR col3 LIKE '%MNO%') 

    Don’t use dynamic SQL, don’t use IF or CASE.

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

Sidebar

Related Questions

I have one report that does not export to excel friendly from SSRS 2005.
I have a SSRS 2005 report that lists data between two particular dates. I
I have an asynchronous local SSRS 2005 report that is of variable height and
Greetings. I have a SSRS 2005 report that shows prices of things. For some
I have a report in SSRS 2005 that has a lot of coulmns in
I have a report in SSRS 2005 that consists of three subreports, all four
I have an 2005 SSRS report that contains two tablix controls; and the report
I have a SSRS report that is Exported to PDF. The report has one
I have develop one ssrs 2005 report. My first question is How to pass
I have a SSRS 2005 report that has a number of images in it.

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.