sql - How to use PIVOT clause over blank values -
sample data:
data table1: prodid type location(there more columns, ignoring them example) p001 t1 l1 p002 t1 l2 p003 t3 l1 p004 t2 p005 t1 l1 need summary type blank [l1] [l2] t1 0 2 1 t2 1 0 0 t3 0 1 0
the problem facing blank values in location field. donno how represent blank location values in pivot query.
pivot query: 1: select type, [] blank, [l1], [l2], blank + [l1] + [l2] total 2: (select type, location table1) 3: pivot 4: (count(location) location in ([],[l1],[l2]) t2 error on line 1 & 4 object or column name missing or empty. select statements, verify each column has name. other statements, empty alias names. aliases defined "" or [] not allowed. add name or single space alias name.
how swapping out null/blank locations dummy value. change
select type, location table1
to
select type, case when location null 'zz' else location end location table1
then column zz or whatever dummy value choose
Comments
Post a Comment