title: SQL return a comma separated value list
body: <p>There are three tables as given below. (I have coded them with data insertions for ease). I need to obtain ValueB in a comma separated list for each row in @TableA</p>
  
  <pre><code>DECLARE @TableA TABLE(IDA INT, ValueA VARCHAR(20))
  DECLARE @TableB TABLE(IDB INT, ValueB VARCHAR(20))
  DECLARE @TableC TABLE(IDC INT, fIDA INT, fIDB INT)
  
  INSERT INTO @TableA(IDA,ValueA)
  SELECT 1, 'aaa'
  UNION 
  SELECT 2, 'bbb'
  UNION 
  SELECT 3, 'ccc'
  UNION
  SELECT 4, 'ddd'
  
  
  INSERT INTO @TableB(IDB, ValueB)
  SELECT 1, 'Option1'
  UNION 
  SELECT 2, 'Option2'
  UNION
  SELECT 3, 'Option3'
  
  
  INSERT INTO @TableC(IDC,fIDA,fIDB)
  SELECT 1,1,1
  UNION
  SELECT 2,1,3
  UNION
  SELECT 3,3,1
  UNION
  SELECT 4,3,2
  UNION
  SELECT 5,4,3
  </code></pre>
  
  <p>Expected output is:</p>
  
  <pre><code>IDA  | ValueA| Options
  -----------------------------------
  1   | aaa   | Option1,Option3
  2   | bbb   | NULL
  3   | ccc   | Option1,Option2
  4   | ddd   | Option3
  </code></pre>
  
  <p>Using TSQL in SQLServer 2005 how can I obtain the above expected output</p>