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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:11:16+00:00 2026-05-31T13:11:16+00:00

actually i need the distinct values from multiple union statements but i do not

  • 0

actually i need the distinct values from multiple union statements but i do not getting this.

My result which i get

here emp_id of 578 has weekend and absent in different rows which i need in single row.

my code goes like this.

             select  [Employee Name],emp_id,holiDAY, 
              leave,absent,weekend
              from  
               (  

                SELECT *FROM    
               (              

                      select  view_emp_info.emp_fullname+' '+'('+''+CONVERT(VARCHAR(50), 


                 (view_emp_info.EMP_ID)) +''+ ')' as [Employee  

               Name],view_emp_info.emp_id,tbl_emp_forceduty.Holiday_Name as 'HOLIDAY'    
                 ,''AS LEAVE,'' AS ABSENT,'' AS [WEEKEND]     
                 from view_emp_Info inner join tbl_emp_forceduty        



                   on view_emp_info.emp_id=tbl_emp_forceduty.emp_id              
                   where           
                   ondate=@date and           
                     view_emp_info.BRANCH_NAME=@branch and view_emp_info.emp_id not in                  

                 (Select emp_id from tbl_emp_attn_log where tdate=@date)              
                 and view_emp_info.status_id=1             

                    union              
                    select view_emp_info.emp_fullname+' '+'('+              

                   ''+CONVERT(VARCHAR(50),view_emp_info.EMP_ID) +''+ ')' as [Employee  

                 Name],view_emp_info.emp_id,'' AS HOLIDAY  

               ,isnull(tbl_org_leave_log.leavetype,' ') 'LEAVE',    
              '' AS 'ABSENT',''AS 'WEEKEND'          
                 from view_emp_info inner join tbl_org_leave_log              
              on view_emp_info.emp_id=tbl_org_leave_log.emp_id              
               where leave_date=@date and view_emp_info.BRANCH_NAME=@branch               
             and  view_emp_info.emp_id not in (Select emp_id from tbl_emp_attn_log where       

            tdate=@date)              
              and tbl_org_leave_log.Taken='0.5' and view_emp_info.status_id=1               

               union         
                 select view_emp_info.emp_fullname+' '+'('+                        

             ''+CONVERT(VARCHAR(50),view_emp_info.EMP_ID) +''+ ')' as [Employee  

            Name],view_emp_info.emp_id,'' AS HOLIDAY ,'' as [LEAVE]    


                ,'' AS 'ABSENT','Weekend'AS 'WEEKEND'          
           from view_emp_info inner join tbl_org_weekend              
          on view_emp_info.emp_id=tbl_org_weekend.emp_id  or tbl_org_weekend.emp_id=0          
     where view_emp_info.BRANCH_NAME=@branch and days=datepart(weekday,@date) and 
         is_weekend=1  and  view_emp_info.emp_id not in (Select emp_id from                                    
        tbl_emp_attn_log where tdate=@date)        

         UNION       
           select view_emp_info.emp_fullname+' '+'('+    

      ''+CONVERT(VARCHAR(50),view_emp_info.EMP_ID) +''+ ')' as [Employee Name],    
         view_emp_info.emp_id,'' AS HOLIDAY,  '' AS 'LEAVE','Absent' as 'ABSENT',''AS  
        'WEEKEND'          
  from view_emp_info inner join tbl_emp_attn_log              
on view_emp_info.emp_id!=tbl_emp_attn_log.emp_id        

             where view_emp_info.BRANCH_NAME=@branch and      
          view_emp_info.emp_id not in (Select emp_id from tbl_emp_attn_log where                                 

        tdate=@date)    



           )    
         T1  where EMP_ID IN (SELECT EMP_ID FROM VIEW_EMP_INFO WHERE              

           BRANCH_NAME=@BRANCH)
            )t2
  • 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-31T13:11:17+00:00Added an answer on May 31, 2026 at 1:11 pm

    Just group by employee_name, employee_id, holiday, leave. Then apply some aggregate functions on the results like max(absent), max(weekend)

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

Sidebar

Related Questions

Hi Programmers! Actually i need the distinct values from the List after adding some
I'm not sure if I actually need this right now but if my app
Let's say, hypothetically (read: I don't think I actually need this, but I am
I'm getting pretty big input string into my method, but what I actually need
When I use this: SELECT DISTINCT id FROM table this works! but... when I
I need a help from ur side. Actually I need to call a method
Actually in one of my project i need to read images from remote server
The title is not very clear. What I actually need to do often is
I need to gather Distinct Id's from a particular table using LINQ. The catch
I actually need help on the thinking process and options, and not really on

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.