title: How to count one to many relationships
body: <p><code>ReporterTbl</code> has a one to many relationship with <code>AttachmentTbl</code>.</p>
  
  <p>In <code>ReporterTbl</code>, I have an ID (101) and I can have <code>AttachmentTbl</code> more than one <code>Attachment</code>s related with <code>ReporterTbl.Id</code></p>
  
  <pre><code>SELECT     
  ISNULL(ReporterTbl.Id, 0) AS Id, 
  CONVERT(char(10), ReporterTbl.StartDate, 101) AS StartDate, 
  ISNULL(ReporterTbl.PriorityId, 0) AS PriorityId, 
  ISNULL(dbo.ReporterTbl.PriorityDesc, '') AS PriorityDesc, 
   (select       
     ReporterTbl.Id, 
     COUNT(dbo.AttachmentTbl.Id) AS attachment_Id
  FROM         
  dbo.AttachmentTbl RIGHT OUTER JOIN
  ReporterTbl ON dbo.AttachmentTbl.Id = ReporterTbl.Id
  GROUP BY ReporterTbl.Id) AS IsAttachment
  )
  </code></pre>
  
  <p>Basically, what I am trying to know is given <code>ReporterTbl.ID</code>, how many <code>Attachment</code>s do I have?</p>
  
  <p>Table structure:</p>
  
  <pre><code> ReporterTbl
  
      Id int   {**PrimaryKey**}
      StartDate datetime
      PriorityId int
      PriorityDesc varchar(500
  
      AttachmentTbl:
  
      AttachmentId indentity
      Id {**FK to ReproterTbl**}
      Filename
      Content
      ...
  </code></pre>