1

Using MS SQL, I like to replace the information in the OEM_Description column when the column Item translation (IT).Description is NULL and when the language setting of the customer C.[Language Code] is English (ENG) into the original item description (I.[Description])

I have come up to this query:

SELECT
    "OEM_Description" = 
CASE 
   WHEN  (C.[Language Code] = 'ENG' and IT.[Description] = NULL)
   THEN I.[Description]
  ELSE IT.[Description]
END,
C.Name as Customer_Name

However the information is only being replaced if I test on "C.[Language Code] = 'ENG'" as soon as i add the test for IT.[Description] = NULL nothing is replaced anymore.

What do I wrong?

3

You don't mention what DBMS, but you probably need IS NULL instead of = NULL. However, you're creating a complex case when this is a texbook use of COALESCE ():

SELECT
    "OEM_Description" = COALESCE( IT.[Description], I.[Description] ),
    C.Name as Customer_Name

Alternate solution based on comment:

IS NULL is not a function but a replacement for = NULL in your original like this:

SELECT
    "OEM_Description" = 
CASE 
   WHEN  (C.[Language Code] = 'ENG' and IT.[Description] IS NULL)
   THEN I.[Description]
  ELSE IT.[Description]
END,
C.Name as Customer_Name
  • Hi Chris, your last change was the solution, I copied the = NULL example from some website, but did not now that this was not the same as IS NULL. Its now working as expected. Thanks! – Herbiek Feb 20 '14 at 20:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.