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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:35:27+00:00 2026-06-18T15:35:27+00:00

I am developing a TSQL query using SSMS 2008 R2 and I want to

  • 0

I am developing a TSQL query using SSMS 2008 R2 and I want to optimize this sproc that currently uses many left joins. There is a lookup table that contains one row / lookup value. So my TSQL code looks like this:

Table A = main record table
Table B = Lookup Table
  row1 x unique_identifier, y varchar(100)
  row2 x unique_identifier, y varchar(100)
  row3 x unique_identifier, y varchar(100)
  row4 x unique_identifier, y varchar(100)

so each row in this lookup table has two values: one unique_identifier and the other value is a varchar. And so currently my sproc code looks like:

select *
FROM A
LEFT JOIN B ON B.X = A.X WHERE B.X = 123456
LEFT JOIN B2 ON B2.X = A.X WHERE B2.X = 123457
LEFT JOIN B3 ON B3.X = A.X WHERE B3.X = 123458
LEFT JOIN B4 ON B4.X = A.X WHERE B4.X = 123459
LEFT JOIN B5 ON B5.X = A.X WHERE B5.X = 123451

I’m sure there must be a more efficient way to do this though. And my real sproc code actually joins this lookup table 30 times instead of 5 times. I have also tried using a temp table but that didn’t seem to optimize it either. Any recommendations for how to replace all of the LEFT JOINs?

OK, so I am updating this question now. This is my exact query:

SELECT DISTINCT 
    lut.[description] as UDT_Injuries,  
    lut2.[description] as abduction, 
    lut3.[description] as ARREST_PARENT
FROM evolv_cs.dbo.incident_header_x x with (nolock)
LEFT JOIN user_defined_lut_rv lut on lut.user_defined_lut_id = x.UDT_Injuries
LEFT JOIN user_defined_lut_rv lut2 on lut2.user_defined_lut_id = x.ABDUCTION
LEFT JOIN user_defined_lut_rv lut3 on lut3.user_defined_lut_id = x.ARREST_PARENT
WHERE lut.[description] IS NOT NULL OR lut2.[description] IS NOT NULL OR lut3.[description] IS NOT NULL 

and the first 10 rows of output for this query:

UDT_Injuries    abduction   ARREST_PARENT
NULL    NULL    Outside of facility
Client  NULL    NULL
Client  NULL    Outside of facility
None    NULL    NULL
None    NULL    Outside of facility
Other adult NULL    NULL
Other adult NULL    Outside of facility
Parent  NULL    NULL
Peer    NULL    NULL
Sibling NULL    NULL

FYI, I looked at the article on PIVOT and UNPIVOT, but I do not want to aggregate any data. Instead I want to translate key id values from incident_header_x into varchar values from user_defined_lut_rv.

Sample data from incident_header_x looks like:

UDT_Injuries    ABDUCTION   ARREST_PARENT
5B84773B-99BF-4EB9-8545-EFC06A35FE29    NULL    NULL
NULL    4F18EDE9-BBBA-4430-9EF4-4E28EAC1E6D4    NULL
5B84773B-99BF-4EB9-8545-EFC06A35FE29    NULL    NULL
NULL    NULL    4F18EDE9-BBBA-4430-9EF4-4E28EAC1E6D4
NULL    NULL    5B84773B-99BF-4EB9-8545-EFC06A35FE29

Does this make sense now what I am trying to achieve? To translate these id values into varchar values from the user_defined_lut_rv lookup table?

  • 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-18T15:35:28+00:00Added an answer on June 18, 2026 at 3:35 pm

    In short, no – there is no more efficient or different way to do this. Are you having performance issues, or are you finding the the code unwieldy?

    Anyway you may wish to do some research on ‘the one true lookup table’, which this looks similar (not identical) to, to get some ideas of disadvantages and advantages in this design.

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

Sidebar

Related Questions

I am developing an SSMS 2008 R2 T-sql query. Currently my query looks like:
I am developing a TSQL stored proc using SSMS 2008 and am receiving the
I am currently developing an online Auction system using ASP.NET 3.5 and SQLServer 2008.
I am developing a T-SQL query in SSMS 2008 R2 which returns one line
Developing for android I need a translate animation. That was easy, but I want
Developing an application for Android, i want to record data that will be usefull
I am writing a T-SQL Query, I am developing the e-commerce website, in that
Developing a web application that I've registered with Twitter. In this app, I might
Developing an app that uses data synchronization. Sending images (even resized) takes time if
I am developing a stored proc for an SSRS 2008 report, but I want

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.