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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:14:11+00:00 2026-05-26T01:14:11+00:00

I have a scenario. Can this be done using one query ? Table Company

  • 0

I have a scenario. Can this be done using one query ?

  • Table Company : Single Company information with CPK as primary key and one Manager,Lead,HR attached to it

  • Table Employees : For every Company there are Employees (1 or more can be up to 500) with unique empID and Manager,Lead,HR attached to it

  • Table Employees Information (for using Web application) : he is assigned with 1 or more Manager,Lead,HR (or can be ALL,ALL,ALL which means he can see everything)

So:

Company
--------
CPK (PK)
Manager
Lead
HR

Employees 
--------
empID (PK)
CPK (FK)
Manager
Lead
HR

EmployeesInfo
-------------
USER_ID (FK)
Manager
Lead
HR

Web –> When a user login he should get all company information.If he has access to that company or any employee within that company then that row is enabled else its greyed out(disable) if its “All” then he can edit every record

For Example:
User1 is assigned to Manager1, Lead1 and HR1.
Then he can edit all records from Company where Manager = Manager1, Lead = Lead1 and HR = HR1.
Also records in Company which has employees with Company.CPK = Employee.CPK and Employee.Manager = Manager1 and Employee.Lead = Lead1 and Employee.HR = HR1

My query till now But

select t2.MANAGER from Employees t2 where t2.CPK  = t1.CPK

returns Multiple record which is expected what should i do ???

SELECT  t1.*,
      --All condition
      CASE WHEN (SELECT MANAGER FROM EmployeesInfo WHERE USER_ID=44) = 'All' then 1
           ELSE(
                --Check for Company
                CASE 
                WHEN t1.MANAGER  in (SELECT MANAGER FROM EmployeesInfo WHERE USER_ID=44) then 1
                WHEN t1.LEAD in (SELECT LEAD FROM EmployeesInfo WHERE USER_ID=44) then 1
                WHEN t1.HR  in (SELECT HR FROM EmployeesInfo WHERE USER_ID=44) then 1
           ELSE(
                --Check Employee M,L,HR for that Company 
                CASE
                WHEN (SELECT t2.MANAGER FROM Employees t2 WHERE t2.CPK  = t1.CPK) in 
                       (SELECT MANAGER FROM EmployeesInfo WHERE USER_ID=44) then 1
                WHEN (SELECT t2.LEAD FROM Employees t2 WHERE t2.CPK = t1.CPK ) in 
                       (SELECT LEAD FROM EmployeesInfo WHERE USER_ID=44) then 1
                WHEN (SELECT t2.HR FROM Employees t2 WHERE t2.CPK  = t1.CPK  ) in 
                       (SELECT HR FROM EmployeesInfo WHERE USER_ID=44) then 1
                ELSE 0 END
                )
           END
           )
      END AS Grey_Out 
FROM Company t1 
WHERE  t1.CPK  ='1234'

Finally I should get all Company with grey_out field as (1 or 0) , then I will use the Grey_Out field for finding whether it should be made editable.

  • 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-26T01:14:11+00:00Added an answer on May 26, 2026 at 1:14 am

    Change

    case
        when (select t2.MANAGER from Table2 t2 where t2.CPK  = t1.CPK) in 
          (Select MANAGER from Table3 where USER_ID=44) then 1
    

    to

    case
        when exists
            (select *
            from 
                Table3 t3
                inner join table2 t2 on t2.manager = t3.manager
            where 
                t3.USER_ID=44 and t2.CPK = t1.CPK) then 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Scenario I have two WCF Services combined in a single App.Config file. I can't
Here's the scenario: I'd like to have a host class that can have a
I have a scenario where I need to upload a file from one web
How can I disable the dangerous eval function? Can that be done using ini_set
I have run into a common dilemma. Many times, our company relies on using
Here's scenario: I have 2 activities and one service First activity is a landing
I have a scenario in which I think I need to lock a table
Does Java have buffer overflows? If yes can you give me scenarios?
I have scenario, I have two update panels on the page (both have update
I have a path defined: when /the admin home\s?page/ /admin/ I have scenario that

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.