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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:44:23+00:00 2026-05-25T02:44:23+00:00

I am having one query given below in that Employee , ShiftAllocation , ShiftMaster

  • 0

I am having one query given below in that Employee, ShiftAllocation, ShiftMaster (two for two shift: Shift1 and shift2) table

SELECT     
   Em.EmployeeId, Em.EmployeeName,
   Sa.ShiftAllocationDate, Sa.ShiftId2, Sa.ShiftId, Sm.ShiftName,
   Sm2.ShiftName AS ShiftName2, Sa.ShiftAllocationId 
FROM        
   ShiftAllocation AS Sa 
INNER JOIN
   EmployeeMaster AS Em ON Sa.EmployeeId = Em.EmployeeId 
LEFT OUTER JOIN
   ShiftMaster AS Sm2 ON Sa.ShiftId2 = Sm2.ShiftId
LEFT OUTER JOIN
   ShiftMaster AS Sm ON Sa.ShiftId = Sm.ShiftId

I am getting this output:

 ShiftAlld EmployeeId  EmployeeName ShiftAllDate shiftId2 ShifId ShiftName ShiftName2 
   1           19          XYZ       2011-08-01 NULL     1     General    NULL
   2           19          XYZ       2011-08-02 NULL     1     General    NULL
   3           19          XYZ       2011-08-02 NULL    -1     NULL       NULL
   4           19          XYZ       2011-08-02 NULL     1     General    NULL
   5           19          XYZ       2011-08-02 NULL    -2     NULL       NULL
   6           19          XYZ       2011-08-02 NULL     1     General    NULL

I want

  • shiftId -1 value should assign ShiftName as Week Off
  • ShiftId -2 value should assign ShiftName as Holiday
  • ShiftId2 NULL value should assign ShiftName2 as Not Assign

I want this output:

ShiftAlld EmployeeId  EmployeeName ShiftAllDate shiftId2 ShifId ShiftName ShiftName2 
   1           19          XYZ       2011-08-01 NULL     1     General    NotAssign  
   2           19          XYZ       2011-08-02 NULL     1     General    NotAssign  
   3           19          XYZ       2011-08-02 NULL    -1     WeekOff    NotAssign  
   4           19          XYZ       2011-08-02 NULL     1     General    NotAssign  
   5           19          XYZ       2011-08-02 NULL    -2     Holiday    NotAssign  
   6           19          XYZ       2011-08-02 NULL     1     General    NotAssign  
  • 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-25T02:44:24+00:00Added an answer on May 25, 2026 at 2:44 am

    You can use a case something like this (untested so there may be any number of typos in there).

    select Em.EmployeeId, 
           Em.EmployeeName,
           Sa.ShiftAllocationDate, 
           Sa.ShiftId2, 
           Sa.ShiftId, 
           case when sa.ShiftId = -1 then 'Week Off'
                when sa.ShiftId = -2 then 'Holiday'
                else sm.ShiftName
           end as ShiftName,
           case when sm2.ShiftId is null then 'Not assigned'
                else Sm2.ShiftName
           end as ShiftName2, 
           Sa.ShiftAllocationId 
    from ShiftAllocation as Sa 
      inner join EmployeeMaster as Em 
        on Sa.EmployeeId = Em.EmployeeId 
      left outer join ShiftMaster as Sm2 
        on Sa.ShiftId2 = Sm2.ShiftId 
      left outer join ShiftMaster as Sm 
        on Sa.ShiftId = Sm.ShiftId
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble writing a query to select one row per date, given
I'm having some problems trying to perform a query. I have two tables, one
Given a ResultMap for an iBatis select query, it seems obligatory that all columns
When designing tables, I've developed a habit of having one column that is unique
I'm having trouble building an Entity Framework LINQ query whose select clause contains method
I am having difficulties with a complicated (for me any way) query. The table
I'm up against a mssql database, having a SQL query like... SELECT id, type,
I am having some issues with the below query, I was unsure as to
Alright. I have a query that looks like this: SELECT SUM(`order_items`.`quantity`) as `count`, `menu_items`.`name`
I have a table. I only need to run one type of query: to

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.