I have a table that has two columns, one with the type of posting and another column with the value.
Source table:
+-----+-------+
|Type | Value |
+-----+-------+
| C | 381.22|
| D | 25.49 |
| C | 25.49 |
| D | 25.48 |
| C | 705.56|
| D | 80.00 |
+-----+-------+
I need to create a view that separates types C and D, and list their values.
I need it to look like this:
+------+-----+
|Credit|Debit|
+------+-----+
|381.22|25.49|
|25.49 |25.48|
|705.56|80.00|
+------+-----+
I tried to create two separate virtual columns with SELECTS, just to list the values for the respective types.
SELECT
(SELECT [value] FROM [table] WHERE [type] IN ('D')) AS Debit,
(SELECT [value] FROM [table] WHERE [type] IN ('C')) AS Credit
And the error occurs because both SELECTS return more than one result:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
Also try to use the PIVOT
statement, but still unsuccessful.
Could you give me a suggestion to solve this problem?