home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.databases.ms-sqlserver      Notorious Rube Goldberg contraption      19,505 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 17,979 of 19,505   
   tshad to All   
   Nulls to 0 in Pivot   
   26 Oct 10 12:06:12   
   
   From: tfs@dslextreme.com   
      
   I am using a pivot (dynamically) and am getting NULL results for some   
   values.   
      
   I want to change the NULLs to 0, but keep getting errors.   
      
   In the following: @strList contains the pivot columns.   
      
   This one works fine except for the nulls:   
      
   SET @sql = '   
   select * from #tfs   
   PIVOT   
   (   
       SUM(Number)   
       for retailer in('+@strList+')   
   ) as pvt   
   '   
      
   I tried:   
      
   SET @sql = '   
   select * from #tfs   
   PIVOT   
   (   
       SUM(Number)   
       for ISNULL(retailer,0) in('+@strList+')   
   ) as pvt   
   '   
   This gets me "incorrect syntax errors"   
      
   I also tried   
      
   SET @sql = '   
   select * from #tfs   
   PIVOT   
   (   
       ISNULL(SUM(Number),0)   
       retailer in('+@strList+')   
   ) as pvt   
   '   
   This one gets 'isnull' is not a recognized aggregate function.   
      
   Thanks,   
      
   Tom   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca