0

This is a sample table and I would like to update the column 'TYPE' as like the value which is there 'STOCKIN' /'STOCKOUT' for the particular DOCNUM in each row.

Sample Table

CODE DOCNUM TYPE
Z01 NUM12 stockin
Z01 NUM12 null
Z01 NUM12 null
Z01 NUM12 null
Z01 NUM134 stockout
Z01 NUM134 null
Z01 NUM134 null
Z01 NUM134 null

Expected table

CODE DOCNUM TYPE
Z01 NUM12 stockin
Z01 NUM12 stockin
Z01 NUM12 stockin
Z01 NUM12 stockin
Z01 NUM134 stockout
Z01 NUM134 stockout
Z01 NUM134 stockout
Z01 NUM134 stockout

Please help me how can I update the column Type for each row as per the DOCNUM.

1
  • 1
    What's the logic to fill those rows? First not null value, min value, max value, anything else? Your question is too vague. Commented Oct 18, 2024 at 11:20

1 Answer 1

0

To update the ‘TYPE’ column based on the ‘DOCNUM’ in your table, you can use SQL to achieve this. Here’s a simple SQL query to update the table.

UPDATE sample_table
SET TYPE = (
    SELECT DISTINCT TYPE
    FROM sample_table AS t2
    WHERE t2.DOCNUM = sample_table.DOCNUM
    AND t2.TYPE IS NOT NULL
)
WHERE TYPE IS NULL;

click here to see full code

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.