Advertisement

TrimwebsolutionsTrimwebsolutions

Problem and Solutions

how to update a tag column based on multiple values against an ID column in SQL ?

By M.K. Verma · 4 May 2022

how to update a tag column based on multiple values against an ID column in SQL ?

If this is just something you want to view, adhoc, then the below will work, as it does not set anything in the tables:

This code will add a column with the status for every line:

SELECT 
    [Customer ID],
    Product,
    Status,
    CASE
        WHEN
            Status = 'Paying'
                THEN
                    'Active'
        WHEN
            Status = 'Paying-Installment'
                THEN
                    'Active'
        ELSE
            'Inactive'
        END AS Active
FROM customerTable

This code will add a column with the status but only show the customer and the status:

SELECT DISTINCT
    [Customer ID],
    CASE
        WHEN
            Status = 'Paying'
                THEN
                    'Active'
        WHEN
            Status = 'Paying-Installment'
                THEN
                    'Active'
        ELSE
            'Inactive'
        END AS Active
FROM customerTable

The difference between the two is what columns are shown, and the DISTINCT command.