Skip to content
Advertisement

Assign a value to a column based on multiple conditions

I have accounting data in SQL. These are entries made for a sale so for every sale made there is an offsetting entry for cost of goods sold as well. In the accounting system we use, it auto generates a transaction id in the TxnId column only for the sales lines not for the cost of goods sold lines for some reason unknown to me. I extract the data using the following query:

The resulting table looks like this:

What I am trying to do is modify the query above to add a column on the end where it places the amount from the sales column in the same row for the cost of goods sold line based on the memo column. I am hoping to get a table that looks like this:

If anyone has any suggestions, they would be greatly appreciated.

Advertisement

Answer

This is what I understood you would want:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement