2017-06-21 52 views
0

我正在接收空值。我怎么能用0代替空值?我已经尝试了pivot和select中的isNull函数,但似乎没有更新。 TY用动态数据透视表中的0替换空值

SET @query ='SELECT * FROM(SELECT 
     petstoreemployee.employeefirstname as employeefirstname 
     ,sum(petID.breed) as breeds 
     ,Format(date, ''MMMM-yyyy'') as Month 

FROM 
     petID, petstoreemployee 
WHERE 
     petID.petstoreemployeeID=petstoreemployee.petstoreemployeeID and 
     petID.ProjectedPrjID=1 
     and 
     (petID.date >= ''2017-01-01 00:00:00:000'' AND petID.date <= 
''2017-12-31 00:00:00:000'') 
    group by petstoreemployee.employeefirstname, Format(date,''yyyy'') 

) 
as d 
PIVOT(
avg(breeds) 
for employeefirstname 
IN (' + @pet + ') 
) as p' 
+0

显示。 –

+0

您应该可以将其添加到特定列的选择上,如@AnthonyHorne所示显示查询在哪里使用过它们 – dbajtr

+0

尝试select语句就像SELECT ISNULL(employeefirstname,'0')AS employeefirstname,ISNULL (品种,'0')作为品种,\t \t \t \t \t ISNULL([Month],'''')As [Month] FROM – 2017-06-21 11:05:50

回答

0

在最外层的SELECT中使用ISNULL()。在你的情况,后SELECT * FROM (

的一个。如果不工作,则更换你在哪里使用ISNULL的SELECT *SELECT ISNULL(column1) etc...