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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:06:29+00:00 2026-06-11T04:06:29+00:00

I’m struggling with a query where I need to join data. I have a

  • 0

I’m struggling with a query where I need to join data.
I have a table with all kinds of status messages. These have a failureBitNr like for example “a1_1”. Then I have a second table that translates “a1_1” to a human readable text (lng_English). By default, the second table has a translation for “a1_1”. But this can also be overwritten by another specific translation, for example when the failureBitNr is used for another status than standard.

So I need to join the status table with the translation table on failureBitNr. That’s not that hard.

But how do I join it on the translation that overwrites the basic translation?

Table 2 looks like this:

id   fileProjectNr MachineNr failureBitNr  lng_English
905  2203456       2         a6_1          This message overwrites the standard
205  NULL          NULL      a6_1          Standard message for a6_1
204  NULL          NULL      a1_1          Standard message for A1_1
203  NULL          NULL      a1_2          Standard message for A1_2

Remark that the message that overwrites the existing one holds a fileProjectNr that is not NULL. All standard messages have a fileProjectNr NULL

So joining only on FailureBitNr will return both rows (905 & 205). But I need to join on failureBitNr and do something with not being NULL of fileProjectNr.

So I did this:

DECLARE @ProjectNr int = 123456

SELECT
    t1.*,
t2.*
FROM
    Table1 AS t1
LEFT JOIN
    Table2 AS t2
ON
(t1.failureBitNr = t2.failureBitNr)
AND
    (t2.fileProjectNr LIKE
    CASE WHEN t2.fileProjectNr = @ProjectNr THEN
        @ProjectNr
    ELSE
        NULL
    END
)
WHERE
    {where statement}

This will return ID 905, however if there is also a join on failureBitNr a1_1 and a1_2, these will all be returned as “NULL” in stead of “Standard message for ax_x”.

Anyone an idea of how to fix this?

  • 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-11T04:06:31+00:00Added an answer on June 11, 2026 at 4:06 am

    My first idea:

    SELECT     t1.*, t2.* FROM     Table1 AS t1 
        LEFT JOIN  Table2 AS t2 (t1.failureBitNr = t2.failureBitNr)
        where t2.fileProjectNr is not NULL
    union all               
        SELECT     t1.*, t2.* FROM     Table1 AS t1 
        LEFT JOIN  Table2 AS t2 (t1.failureBitNr = t2.failureBitNr) and 
        where t1.failureBitNr not in (select failureBitNr from Table2 where fileProjectNr is not NULL)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a number of different data sources that I need to query and
I have the following query which is takin 3 seconds on a table of
I'm struggling. I have query against my db that returns a single column of
I am struggling to append data retreived from an SQL query in PHP. Basically
i'm struggling with Xpath, i have an xml list and i need to get
I'm struggling with a query where I need to SUM DISTINCT Rows. There has
I have a need to build a MySQL query to notify users of a
I'm struggling with correct procedure for executing SQL query. Basically, I have text field
I have an awkward mySQL query to make and I'm struggling due to a
I have n:m table which links data between two tables: id | category -------------

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.