title: SP return null as ZERO?
body: <p>Using a stored procedure i have a fairly complex SQL statement which returns a COUNT value as a pseudo column. In many cases the result will be 'null'. This causes problems in my application, so i am wondering if it is possible to return a 'null' as '0' by default from the stored procedure?</p>
  
  <p>Thanks.</p>
  
  <p>UPDATE</p>
  
  <p>I need to apply the ISNULL to the following statement;</p>
  
  <pre><code>    select recip_Chosen, recip_CampaignId) AS ChosenCount
      from TBL_CAMPAIGNRECIPIENTS
      WHERE recip_CampaignId =  @campaign
      group by recip_Chosen
  </code></pre>
  
  <p>Which should be something like;</p>
  
  <pre><code>    select recip_Chosen, ISNULL(count(recip_CampaignId),0) AS ChosenCount
      from TBL_CAMPAIGNRECIPIENTS
      WHERE recip_CampaignId =  @campaign
      group by recip_Chosen
  </code></pre>
  
  <p>However, this still returns null(s) in the ChosenCount column. Any ideas?</p>
  
  <p>UPDATE</p>
  
  <p>Ok so the above statement is part of a much larger one as shown below. Here is the full Stored Procedure, but not the table structure since it involves several tables. I only need 'ChosenCount' to return '0' instead of Null. The SP does return 1 row for each record in TBL_CAMPAIGNS_CHARITIES where it corresponds to TBL_CAMPAIGNS. </p>
  
  <pre><code>CREATE PROCEDURE web.getPublicCampaignData
     (
     @campaign BIGINT
     )
  AS
  BEGIN
  
  SELECT * 
  FROM TBL_CAMPAIGNS C
  INNER JOIN TBL_MEMBERS M
      ON C.campaign_MemberId = M.members_Id
  INNER JOIN TBL_CAMPAIGNS_CHARITIES CC
      ON C.campaign_Key = CC.camchar_CampaignID
  INNER JOIN TBL_CHARITIES CH
      ON CC.camchar_CharityID = CH.cha_Key
  LEFT OUTER JOIN (
      select recip_Chosen, count(recip_CampaignId) as ChosenCount
      from TBL_CAMPAIGNRECIPIENTS
      WHERE recip_CampaignId =  @campaign
      group by recip_Chosen
  ) CRC
  on CH.cha_Key = CRC.recip_Chosen
  WHERE C.campaign_Key = @campaign;
  
  END
  </code></pre>