Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
cognos79
Posting Yak Master
241 Posts |
Posted - 2010-07-29 : 12:13:14
|
when I do pivot on date column...if some of the dates are not in the table then pivot returns null, but I want to show 0 in the column.exec('select pvt.*from #finalpivot ( sum(totCount) for attend_date in (' + @dates +')) as pvt') |
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2010-07-29 : 12:32:36
|
List the columns rather than pvt.*, but I think this works, but I havn't worked with a pivot in a little while.exec ('select pvt.col1,pvt.col2,pvt.etc, coalesce(totcount,0) as Totcountfrom #finalpivot (sum(totCount)for attend_date in (' + @dates +')) as pvt' Success is 10% Intelligence, 70% Determination, and 22% Stupidity.\_/ _/ _/\_/ _/\_/ _/ _/- 881 |
 |
|
cognos79
Posting Yak Master
241 Posts |
Posted - 2010-07-29 : 12:36:39
|
the number columns in the pivot is dynamic...so I wont be able to list them. |
 |
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2010-07-29 : 13:51:52
|
Please show some sample data if this is not what you want.exec('select pvt.col1,pvt.col2,pvt.etc, coalesce(totcount,0) as Totcountfrom #finalwhere not totcount is nullpivot(sum(totCount)for attend_date in (' + @dates +')) as pvt' Success is 10% Intelligence, 70% Determination, and 22% Stupidity.\_/ _/ _/\_/ _/\_/ _/ _/- 881 |
 |
|
|
|
|
|
|