title: Collate declared SQL variable
body: <p>I've been looking at <a href="https://stackoverflow.com/a/3917698/241211">this code,</a> reproduced below, that looks for non-ASCII characters...</p>
  
  <pre><code>select line,
    patindex('%[^ !-~]%' COLLATE Latin1_General_BIN, Line) as [Position],
    substring(Line, patindex('%[^ !-~]%' COLLATE Latin1_General_BIN, Line), 1) as [InvalidCharacter],
    ascii(substring(line, patindex('%[^ !-~]%' COLLATE Latin1_General_BIN, Line), 1)) as [ASCIICode]
  from staging.APARMRE1
  where patindex('%[^ !-~]%' COLLATE Latin1_General_BIN, Line) &gt; 0
  </code></pre>
  
  <p>and it just strikes me that I'd want to declare a variable for <code>'%[^ !-~]%' COLLATE Latin1_General_BIN</code> instead of writing it out every time, but</p>
  
  <pre><code>declare @regex varchar(20) = '%[^ !-~]%' COLLATE Latin1_General_BIN;
  
  select line,
    patindex(@regex, Line) as [Position],
    substring(Line, patindex(@regex, Line), 1) as [InvalidCharacter],
    ascii(substring(line, patindex(@regex, Line), 1)) as [ASCIICode]
  from staging.APARMRE1
  where patindex(@regex, Line) &gt; 0
  </code></pre>
  
  <p>just doesn't do the same thing. Am I just missing some syntax? Is it impossible?</p>