I have a table as below “table1” –
Here value is of type “nvarchar(300)” but it contains both numeric string and string values.
ID | DocID | Name | Value |
---|---|---|---|
1 | 4 | A | 1234 |
1 | 4 | B | false |
2 | 4 | A | null |
2 | 4 | B | 2 |
expected result is “table2” –
| ID | DocID |A|B|
| ——– | ——– |—-|—-|
|1 | 4 |1234|false|
|2| 4|null|2|
I am using below query to achieve the desired output
max(case when name='A' then value end) as A,
max(case when name='B' then value end) as B,
max(case when name='C' then value end) as C,
max(case when name='D' then value end) as D
from table1 group by id,docid```
This query is showing below result -
| ID | DocID |A|B|
| -------- | -------- |----|----|
|1 | 4 |null|false|
|2| 4|null|null|
It is not showing value for numeric string like "1234" and "2". How can I achieve the correct result?
expected result is "table2" -
| ID | DocID |A|B|
| -------- | -------- |----|----|
|1 | 4 |1234|false|
|2| 4|null|2|
New contributor
Tina is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.