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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:10:46+00:00 2026-06-07T03:10:46+00:00

I have a typical question with a twist. I need to modify the following

  • 0

I have a typical question with a twist.

I need to modify the following T SQL query. Currently it only looks in one table for information. I need to look into two tables with identical columns for information. One table contains current employees and one contains former employees

SELECT t.net_Id
      ,e.fname
      ,e.lname
FROM tblTrackingEmployee t
    join view_employee e 
        on e.net_id = t.net_id
where trackingid = @trackingId
and empType = @empType

What I was thinking of doing is using a union to look in both. An employee will either appear in one table or the other, it will never be in both.

SELECT t.net_Id
      ,e.fname
      ,e.lname
FROM tblTrackingEmployee t
    JOIN view_employee e
        ON e.net_id = t.net_id
WHERE trackingid = @trackingId
AND empType = @empType
union 
SELECT t.net_Id
      ,fe.fname
      ,fe.lname
FROM tblTrackingEmployee t
      JOIN view_employee fe 
             ON fe.net_id = t.net_id
WHERE trackingid = @trackingId
AND empType = @empType

However here is the twist, I need to know if the person/s returned are current or former employees. Is there a way to add a column to the returned table that has a 1 if its a current employee or 0 if its a former employee? Each trackingId can potentially contain both types of employees.

  • 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-06-07T03:10:48+00:00Added an answer on June 7, 2026 at 3:10 am

    Add a constant column to each SELECT clause – you can alias it:

    SELECT t.net_Id
          ,e.fname
          ,e.lname
          ,'Current' AS Type
    FROM tblTrackingEmployee t
        JOIN view_employee e
            ON e.net_id = t.net_id
    WHERE trackingid = @trackingId
    AND empType = @empType
    union 
    SELECT t.net_Id
          ,fe.fname
          ,fe.lname
          ,'Former'
    FROM tblTrackingEmployee t
          JOIN view_formerEmployee fe 
                 ON fe.net_id = t.net_id
    WHERE trackingid = @trackingId
    AND empType = @empType
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a typical dev scenario: I have a SQL 2008 database that I
My question is similar this one here: ResultsController to another ResultsController A typical app
For my first question, I have your typical web e-com scenario where the user
Simple question, but is the solution? I have a typical C# Application that runs
I have a typical Persons table and an Orders table defined in such a
I have a question regarding RouteLink vs. ActionLink. Consider the following route routes.MapRoute(Routename1, {someEnum}/SpecificAction/{id}/{stringId},
I have List collection with around 35,000 strings Typical string looks like this: <i>füüs</i>ampri
So i have a question. Say you have a table requests, which represent a
I have a question regarding Caching. I have a typical n-tier ASP.NET web app.
New to DDD here and have a architecture question which should be a typical

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.