Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Reporting Services - How to define the WHERE clause dynamically ?

Reporting Services - How to define the WHERE clause dynamically ?

Scheduled Pinned Locked Moved C#
csharpasp-nettutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    davebarkshire
    wrote on last edited by
    #1

    We are about to start using Reporting Services which will be accessed from a C# ASP.net application. Many reports will have a different where clause for the same report depending upon who the user is and the circumstances. Therefore, I need to be able to send the report a WHERE clause ideally as a string. I can't use hard defined parameters because they will be on different fields depending on how I want to call the report. Can anyone tell me how this is done?

    L 1 Reply Last reply
    0
    • D davebarkshire

      We are about to start using Reporting Services which will be accessed from a C# ASP.net application. Many reports will have a different where clause for the same report depending upon who the user is and the circumstances. Therefore, I need to be able to send the report a WHERE clause ideally as a string. I can't use hard defined parameters because they will be on different fields depending on how I want to call the report. Can anyone tell me how this is done?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You'd get more responses from the database-forum. I haven't used the Reporting Services yet, but I guess that they can use a function or sproc as a datasource. I usually use a construction that's comparable to this;

      DECLARE @TEST AS TABLE
      (FieldOne VARCHAR(10))
      INSERT INTO @TEST VALUES('Hello')
      INSERT INTO @TEST VALUES('World')

      DECLARE @ArgumentForFieldOne AS VARCHAR(10)
      SET @ArgumentForFieldOne = 'He%'

      SELECT *
      FROM @TEST
      WHERE (
      (@ArgumentForFieldOne IS NOT NULL AND FieldOne LIKE(@ArgumentForFieldOne))
      OR (@ArgumentForFieldOne IS NULL)
      )

      You'd set @ArgumentForFieldOne to NULL if you don't want to search that particular field. This has the disadvantage that you can't pass NULL as a parameter to search for though. You can bypass this problem by introducing a separate bit that indicates whether you want to filter the field or not;

      DECLARE @TEST AS TABLE
      (FieldOne VARCHAR(10))
      INSERT INTO @TEST VALUES('Hello')
      INSERT INTO @TEST VALUES('World')

      DECLARE @DoFilterFieldOne AS BIT
      SET @DoFilterFieldOne = 1
      DECLARE @ArgumentForFieldOne AS VARCHAR(10)
      SET @ArgumentForFieldOne = 'He%'

      SELECT *
      FROM @TEST
      WHERE (
      (@DoFilterFieldOne = 1 AND FieldOne LIKE(@ArgumentForFieldOne))
      OR (@DoFilterFieldOne = 0)
      )

      You can wrap these constructions in a table-valued function, but a sproc where you pass @DoFilterFieldOne and @ArgumentForFieldOne is also an option.

      SQL lingua venusta :)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups