Need help in understanding this SQL query

Newbie

Can someone please help me in understanding this SQL code? This is what is actually confusing me more - END = G.CODE

SELECT something, something
FROM ABCD A
JOIN GHIJ G ON 
    CASE    
        WHEN A.CODE = 'not available' THEN 'NA_CODE'
        ELSE A.CODE END = G.CODE
                   LEFT JOIN PRODUCT P ON P.ID = A.ID
                   WHERE P.ID IS NULL;
GO          

Thanks Isha

RanchiRhino

When you look at properly formatted code you will understand it.

CASE WHEN A.CODE = 'not available' THEN 'NA_CODE' ELSE A.CODE END = G.CODE

consider the join clause like

 B.XYZ = G.CODE

Where B.XYZ is a case statement for manipulating joining column A.CODE for values 'not available' to 'NA_CODE' so that it could match same value in G.CODE. Except the value 'not available' everything is fine so the case statement only manipulates 'not available' to 'NA_CODE', so that join clause could match it with value inside G.CODE.

Look for case statement for more details.

Hope you understood.

Here :-

B.XYZ =[CASE WHEN A.CODE = 'not available' THEN 'NA_CODE' ELSE A.CODE END]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related