Teddy B
Jun 13 2011, 03:23 PM
I have a crosstab query that uses a Count as the Value. Sometimes I get null value in my crosstab query results. Is there any easy way to change my SQL so that my nulls appear as a 0 in my crosstab results?
Here is a simple sample SQL of a crosstab:
TRANSFORM Count([ZooTable].[AnimalNames]) AS ([CountOfAnimalNames])
SELECT [ZooTable].[AnimalTypes]
FROM ZooTable
GROUP BY [Zootable].[AnimalTypes]
PIVOT [ZooTable].[ZooLocation];
Thanks for reading my post! Teddy
JonSmith
Jun 13 2011, 03:26 PM
Replace the field with
IIF(Isnull([ZooTable].[AnimalTypes]),0,[ZooTable].[AnimalTypes])
and it should work
John Spencer
Jun 13 2011, 04:00 PM
TRANSFORM CLng(NZ(Count([ZooTable].[AnimalNames]),0)) AS ([CountOfAnimalNames])
SELECT [ZooTable].[AnimalTypes]
FROM ZooTable
GROUP BY [Zootable].[AnimalTypes]
PIVOT [ZooTable].[ZooLocation];
Teddy B
Jun 14 2011, 09:23 AM
Thanks for the reply Guys!
John, I ended up using your solution. Always a pleasure to see your reply on one of my posts!
JonSmith
Jun 14 2011, 11:32 AM
I always forget about the Nz function, Johns was the better solution.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.