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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:26:33+00:00 2026-06-16T00:26:33+00:00

I have this query below, its working fine, and I’m getting what I need.

  • 0

I have this query below, its working fine, and I’m getting what I need. All I need to know is, is this right way to write this query as this or is there any way to shorten it?

I have 4 tables, 1st has branch information, 2nd has customer information, 3rd has engineer information, 4th has service calls information.

In service calls table, 3 columns match with 3 different engineer names

Here is the query

SELECT
    B.BranchName, C.Name AS CustomerName,D.FullName AS CallOpenedBy,
    A.CallOpenTime, A.CallMode, A.CallType, A.ReportedBy, 
    A.ReportedVia, A.ReportedProblem,
    A.MaterialsReceived, A.MisComments, A.CallPriority, A.EstimatedAmount,
    E.FullName AS EngineerName,  
    A.ActionTaken, A.CallClosedTime, 
    F.FullName AS CallClosedBy, A.Status, 
    A.Amount 
FROM
    TblServiceCalls A
INNER JOIN 
    TblBranchInfo B ON A.BranchID = B.BranchID
INNER JOIN 
    TblMainMaster C ON A.MasterID = C.MasterID
INNER JOIN 
    TblUserProfiles D ON A.CallOpenedBy = D.UserProID
INNER JOIN 
    TblUserProfiles E ON  A.Engineer = E.UserProID
INNER JOIN 
    TblUserProfiles F ON  A.CallClosedBy = F.UserProID

Can I shorten the query in last 3 lines? Thanks you guys in advance 🙂

  • 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-16T00:26:34+00:00Added an answer on June 16, 2026 at 12:26 am

    No you can not, you are using D, E, and F in your result set so you must join those tables. You could only remove them if you removed things like D.FullName AS CallOpenedBy and E.FullName AS
    EngineerName
    and F.FullName AS CallClosedBy from your result.


    As a side note (and the I bet the original reason you asked this question), but if a call has not been closed yet and A.CallClosedBy has not been assigned to a value in F.UserProID the row will be excluded from the result.

    You should be using LEFT OUTER JOIN for those 3 tables if any of the 3 columns they link on may not have a corresponding record in the destination table or could be null.

    Here is how I would do it

    Select B.BranchName, C.Name AS CustomerName,IsNull(D.FullName, '(Not Assigned)') AS CallOpenedBy,
    A.CallOpenTime,A.CallMode, A.CallType,A.ReportedBy, A.ReportedVia, A.ReportedProblem,
    A.MaterialsReceived, A.MisComments,A.CallPriority,A.EstimatedAmount,IsNull(E.FullName, '(Not Assigned)') AS        
    EngineerName, A.ActionTaken, A.CallClosedTime,IsNull(F.FullName, '(Not Assigned)') AS CallClosedBy, A.Status, 
    A.Amount From TblServiceCalls A
    INNER JOIN TblBranchInfo B ON A.BranchID = B.BranchID
    INNER JOIN TblMainMaster C ON A.MasterID = C.MasterID
    LEFT OUTER JOIN TblUserProfiles D ON A.CallOpenedBy = D.UserProID
    LEFT OUTER JOIN TblUserProfiles E ON  A.Engineer = E.UserProID
    LEFT OUTER JOIN TblUserProfiles F ON  A.CallClosedBy = F.UserProID
    

    Now if the value is NULL or the record does not exist in the destination table it will say (Not Assigned) in the output instead of excluding the row.

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

Sidebar

Related Questions

I have written this query for retrieving data from mysql as below select FeedbackCode,EMailID,FeedbackDetail,
I have below query I am trying to show message 'No SubSource for this
I don't know why but the code below is working when I have a
I written a small query and in Linqpad its working well but (see below)
I currently have a $.getJSON call which is working fine as shown below. var
I have a query which is working fine: BULK INSERT ZIPCodes FROM 'e:\5-digit Commercial.csv'
This query was working for me until recently. I now have 135 InstallationSummary documents
Have this query: SELECT HOUR( DATE ) AS hr, COUNT( * ) AS cnt
I have this query... SELECT Distinct([TargetAttributeID]) FROM (SELECT distinct att1.intAttributeID as [TargetAttributeID] FROM AST_tblAttributes
I have this query which on executing in my sql command line client executes

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.