title: TSQL - Case statement + Concatenate 2 columns + select 10 characters from right in one
body: <p>I'm trying to concatenate two fields in a case statement, where I only want the 10 characters from the right for the second field.  The first field is a 25-character varchar field (twfcompID); the second field is a text field (t.TransNotes).  I want to end up with something that looks like 497-2059--281369.pdf.   Here is my syntax that isn't working.</p>
  
  <pre><code>(Case
      WHEN l.TWFCompID = 'FCLMIL' THEN    
          CAST(m.MatterID AS VARCHAR(100)) + '--' + 
          RIGHT(CAST(t.TransNotes,10) AS VARCHAR(100))
      WHEN l.TWFCompID like 'f-%' THEN
          CAST(m.MatterID AS VARCHAR(100)) + '--' + (right(t.TransNotes,10) AS VARCHAR(100)) 
      WHEN l.TWFCompID like 'FS-%' THEN
          CAST(m.MatterID AS VARCHAR(100)) + '--' + CAST(right(t.TransNotes,10) AS VARCHAR(100)) 
  ELSE '' END) AS 'LineItemID', 
  </code></pre>
  
  <hr>
  
  <p>When I run this, I get the error:
  Msg 1035, Level 15, State 10, Line 5
  Incorrect syntax near 'CAST', expected 'AS'.</p>