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

  • Home
  • SEARCH
  • 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 630845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:54:00+00:00 2026-05-13T19:54:00+00:00

I have a brain-teaser for all you SQL Server 2008 Reporting gurus out there

  • 0

I have a brain-teaser for all you SQL Server 2008 Reporting gurus out there 🙂

I have a report which displays a bunch of data, including the UserID and OrgUnitID for users. It’s a server report which I’m rendering on the server, from within an ASP.NET application.

My requirement is that

  • a “normal” user can only see his own data rows (basically
    SELECT (fields) FROM dbo.DataView WHERE UserID = @UserID)

  • a privileged user can see all his subordinates; I have a table-valued function which delivers that functionality (basically SELECT (fields) FROM dbo.DataView
    INNER JOIN dbo.OrgHierarchy ON DataView.OrgUnitID = OrgHierarchy.OrgUnitID
    )

Both scenarios in themselves work just fine – trouble is: I should combine those into a single report.

How can I do this?? How can I have a report that dynamically, based on a report parameter I pass in (@UserLevel; 0 = normal user, 1 = privileged) uses one query or the other??

I don’t really feel like getting into dynamically rewriting the SQL query…. any other ideas??

  • I was thinking about having two separate distinct datasets and then just activating the “right” one based on the UserLevel parameter – but I can’t seem to find out how to define a data set on a subreport or a textbox……

  • Then I was hoping I might be able to add a filter to my dataset on my server report dynamically, from my client app – but that doesn’t seem to be possible, either….. could I create a filter for the “UserID = @UserID” setting and somehow enable/disable it as needed, in embedded VB Code on the report itself?

Any takers? Wild outside-the-box thoughts? Let me know!

  • 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-13T19:54:01+00:00Added an answer on May 13, 2026 at 7:54 pm

    can you try to make one query that works for everyone? here is just a guess based on the table/columns you include in your question:

    --always returns the data for the one given @UserID
    SELECT
        (fields) 
        FROM dbo.DataView 
        WHERE UserID = @UserID
    UNION
    --only returns data for the subordinates of @UserID, nothing if there are none
    SELECT
        (d2.fields)
        FROM dbo.DataView               d1 
            INNER JOIN dbo.DataView     d2 ON d1.OrgUnitID = d2.OrgUnitID 
            INNER JOIN dbo.OrgHierarchy  h ON d1.OrgUnitID = h.OrgUnitID
        WHERE d1.UserID = @UserID and d1.UserLevel=1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.