title: SQL Server - STRING_AGG separator as conditional expression
body: <p>I need to concatenate rows using different separator based on arbitrary logic. For instance:</p>
  
  <pre><code>CREATE TABLE t(i INT, c VARCHAR(10));
  INSERT INTO t(i,c) VALUES(1, 'a'),(2, 'b'),(3, 'c'),(4, 'd'),(5, 'e');
  
  SELECT STRING_AGG(c,(CASE WHEN i%2=0 THEN ' OR ' ELSE ' AND ' END)) 
         WITHIN GROUP (ORDER BY i) AS r
  FROM t;
  </code></pre>
  
  <p><strong><a href="https://dbfiddle.uk/?rdbms=sqlserver_2017&amp;fiddle=c878b8bf759971645c25cb797c03dc55" rel="nofollow noreferrer">db&lt;>fiddle demo</a></strong></p>
  
  <p>And it ends with error:</p>
  
  <blockquote>
    <p>Separator parameter for STRING_AGG must be a <strong>string literal</strong> or <strong>variable</strong>.</p>
  </blockquote>
  
  <p>My end goal is to get: <code>a OR b AND c OR d AND e</code> like in: <strong><a href="https://dbfiddle.uk/?rdbms=postgres_11&amp;fiddle=1ff9615f1101bff256196fb14e0c0040" rel="nofollow noreferrer">db&lt;>fiddle demo</a></strong></p>
  
  <hr>
  
  <p>Notes: I am aware of <code>XML + STUFF</code> or <code>@var = @var + ...</code>.</p>
  
  <p>I am searching for "workarounds" specific to <code>STRING_AGG</code>.</p>
  
  <hr>
  
  <p>EDIT: I've added it as sugestion on <a href="https://feedback.azure.com/forums/908035-sql-server/suggestions/36809734-string-agg-with-non-constant-expression-as-separat" rel="nofollow noreferrer">Azure Feedback</a></p>