I am trying to create a view in SQL Server 2012 that excludes columns where the entry is null (represent by 0 here so it's easier to read). My base data is this
╔════╦══════╦══════╦══════╦══════╦══════╗
║ ID ║ Col1 ║ Col2 ║ Col3 ║ Col4 ║ Col5 ║
╠════╬══════╬══════╬══════╬══════╬══════╣
║ 1 ║ 1 ║ 0 ║ 0 ║ 0 ║ 5 ║
║ 2 ║ 1 ║ 2 ║ 3 ║ 0 ║ 5 ║
║ 3 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║
║ 4 ║ 0 ║ 2 ║ 3 ║ 0 ║ 0 ║
╚════╩══════╩══════╩══════╩══════╩══════╝
What I would like to return would be
╔════╦══════╦══════╦══════╦══════╗
║ ID ║ Res1 ║ Res2 ║ Res3 ║ Res4 ║
╠════╬══════╬══════╬══════╬══════╣
║ 1 ║ 1 ║ 5 ║ 0 ║ 0 ║
║ 2 ║ 1 ║ 2 ║ 3 ║ 5 ║
║ 3 ║ 0 ║ 0 ║ 0 ║ 0 ║
║ 4 ║ 2 ║ 3 ║ 0 ║ 0 ║
╚════╩══════╩══════╩══════╩══════╝
In this case, since column 4 had value 0 in all entries it was not included as a result. ID1 returned 1 and 5 skipping the 0s, and had 0s to fill since ID2 had 4 columns. If all values were 0, this would either just return Res1 with 0 or no columns and just the IDs.
Hope this is clear. I'm having trouble explaining it.