title: sql-server: Incorrect syntax near ','
body: <p>I receive this syntax error when I execute the following query. Any suggestions how to fix it? </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>The query is created dynamically, the size of the query that runs is >8000...</p>
  
  <blockquote>
    <p>Incorrect syntax near ','.</p>
  </blockquote>
  
  <pre><code>SELECT TS.* , --comma added
         (SELECT CONVERT(DATETIME, [4501001], 103) AS 'AG_VISDATE.U1.[4501001]'
          FROM   form.AG_VISDATE
          WHERE  pid = TS.pid
                 AND COALESCE(visid, '') = 'U1'),
         (SELECT [4501004] AS 'AG_VISDATE.U1.[4501004]'
          FROM   form.AG_VISDATE
          WHERE  pid = TS.pid
                 AND COALESCE(visid, '') = 'U1') 
  </code></pre>
  
  <p>I added the ',' after <code>TS.*</code> but now I receive these errors:</p>
  
  <blockquote>
    <p>Msg 102, Level 15, State 1, Line 1
    Incorrect syntax near ','.</p>
    
    <p>Msg 102, Level 15, State 1, Line 1
    Incorrect syntax near 'TS'.</p>
  </blockquote>