title: String.Join in SQL
body: <p>i want to select from a Table called <code>RMA</code>(simplified):</p>
  
  <pre><code> idRMA| RMA_Number
   -----------------------
   1      RMA0006701
   2      RMA0006730
   3      RMA0006736
   4      RMA0006739
   5      RMA0006742
  </code></pre>
  
  <p>There is a  junction table between <code>RMA</code> and <code>tdefSymptomCode</code> called <code>trelRMA_SymptomCode</code>:</p>
  
  <pre><code> fiSymptomCode| fiRMA
   -----------------------
   1              1
   1              2
   2              2
   5              3
   7              3
   8              3
   2              5
   3              5
   4              5
   5              5
  </code></pre>
  
  <p>for the sake of completeness, this is <code>tdefSymptomCode</code>:</p>
  
  <pre><code>idSymptomCode    SymptomCodeNumber      SymptomCodeName
  1                0000                   Audio problem
  2                0100                   SIM problem
  3                0200                   Appearance problem
  4                0300                   Network problem
  5                0500                   On/Off problem
  </code></pre>
  
  <h2>Q:</h2>
  
  <p><strong>every RMA can have 0-5 SymptomCodes. How can i join the SymptomCodeNumber with a delimiter like ':' together in a scalar-valued-function, so that i only get one varchar-value as result.</strong></p>
  
  <p>Something like this(where <code>getRmaSymptomCodes</code> is a SVF):</p>
  
  <pre><code>SELECT idRMA, RMA_Number, dbo.getRmaSymptomCodes(idRMA,':') AS Symptoms FROM RMA
  </code></pre>
  
  <p>This could be the symptoms of 3 different RMA's (all have exactly one symptom):</p>
  
  <pre><code>RMA_Number    SymptomCodeNumber
  RMA0004823    0100
  RMA0004823    0200
  RMA0000083    0300
  RMA0000084    0300
  RMA0000084    0400
  </code></pre>
  
  <p>That should be concatenated as:</p>
  
  <pre><code>RMA0004823    0100:0200
  RMA0000083    0300
  RMA0000084    0300:0400
  </code></pre>
  
  <p>Thank you in advance</p>
  
  <p><strong>Update</strong>: Thanks to all i have created this working function</p>
  
  <pre><code>CREATE FUNCTION [dbo].[getRmaSymptomCodes]
  (
      @idRMA int,
      @delimiter varchar(5)
  )
  RETURNS VARCHAR(8000)
  AS
  BEGIN
      DECLARE @Codes VARCHAR(8000) 
      SELECT @Codes = COALESCE(@Codes + @delimiter, '') +  tdefSymptomCode.SymptomCodeNumber
      FROM  RMA INNER JOIN
          trelRMA_SymptomCode ON RMA.IdRMA = trelRMA_SymptomCode.fiRMA INNER JOIN
          tdefSymptomCode ON trelRMA_SymptomCode.fiSymptomCode = tdefSymptomCode.idSymptomCode
      where idRMA=@idRMA
      order by SymptomCodeNumber
      return @Codes
  END
  </code></pre>