Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your question "--EDIT--" made all the difference: <br>First, combining your original error message (in the question title), with your new comments (esp. <code>error occurs when I choose multiple territory managers</code>), it starts sounding like a problem with trying to give a list to an <code>IN</code> clause, where quotes or commas are not arranged properly... perhaps something intended to be <strong>code</strong> is being interpreted as part of the <strong>values</strong>, or vice versa.</p> <p>Next, looking at the rest of the code (esp. your <code>WHERE</code> clause), there is indeed an 'IN' clause for territory managers, with a parameter passed to it: </p> <blockquote> <p>and a.TerritoryManagerID in (SELECT Id FROM TM_CTE UNION ALL SELECT CASE WHEN @TM in (0) Then ID else 99999 end FROM TerritoryManagers )</p> </blockquote> <p>So, the next question is: What exactly does that <code>(0)</code> look like, when it contains 1 territory manager, and when it contains multiple territory managers? </p> <p>Passing multiple values to feed an <code>IN</code> clause may need to be done indirectly... you might end up either: <br> (1) using <em>dynamic SQL</em> (creating the <code>SELECT</code> as a string, then using <code>EXECUTE</code> or <code>sp_executesql</code> to execute that string), or <br> (2) making the territory managers list a short table, maybe even passing that table as a parameter to the stored procedure... then (2a) using <code>IN (SELECT t FROM t_list)</code> (where <code>t_list</code> is the table), or (2b) <code>JOIN</code>ing to that table. </p> <p>Hope that helps... </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload