title: Procedure or function has too many arguments specified SSRS
body: <p>For some reason I am able to run my <code>SELECT</code> statement in SSMS, but when I use it in SSRS then it says <code>Procedure or function has too many arguments specified</code>.
  If I choose only one parameter - it gives me the result. But if I choose 2 or more - I got an error.</p>
  <p>This is my whole code:</p>
  <pre><code>DECLARE @ClassCode varchar(max) = '31439,739889'
  CREATE TABLE #PolicyNumbers  (PolicyNumber varchar(50))
  INSERT INTO #PolicyNumbers SELECT  PolicyNumber FROM tblClassCodesPlazaCommercial T1
  WHERE NOT EXISTS (SELECT 1 FROM tblClassCodesPlazaCommercial T2  
  WHERE  T1.PolicyNumber = T2.PolicyNumber
          AND ClassCode  IN 
          (SELECT * FROM [dbo].[StringOfStringsToTable](@ClassCode,','))) 
  ; WITH Earned_to_date AS (
     SELECT Cast('11-30-2016' AS DATE) AS Earned_to_date
  ), policy_data AS (
      SELECT
          PolicyNumber
  ,       Cast(PolicyEffectiveDate AS DATE) AS PolicyEffectiveDate
  ,       Cast(PolicyExpirationDate AS DATE) AS PolicyExpirationDate
  ,       WrittenPremium
          FROM PlazaInsuranceWPDataSet pid
          WHERE  NOT EXISTS (SELECT PolicyNumber FROM #PolicyNumbers pn WHERE pn.PolicyNumber = pid.PolicyNumber )
          AND State IN ('CA','NV','AZ') 
          
  ) 
  
  , digits AS (
  SELECT digit
     FROM (VALUES (0), (1), (2), (3), (4)
  ,      (5), (6), (7), (8), (9)) AS z2 (digit)
  ), numbers AS (
  SELECT 1000 * d4.digit + 100 * d3.digit + 10 * d2.digit + d1.digit AS number
      FROM digits AS d1
      CROSS JOIN digits AS d2
      CROSS JOIN digits AS d3
      CROSS JOIN digits AS d4
  ), calendar AS (
  SELECT
      DateAdd(month, number, '1753-01-01') AS month_of
  ,   DateAdd(month, number, '1753-02-01') AS month_after
      FROM numbers
  ), policy_dates AS (
  SELECT
     PolicyNumber
  ,   CASE
          WHEN month_of &lt; PolicyEffectiveDate THEN PolicyEffectiveDate
          ELSE month_of
      END AS StartRiskMonth
  ,   CASE
         WHEN PolicyExpirationDate &lt; month_after THEN PolicyExpirationDate
         WHEN Earned_to_date.Earned_to_date &lt; month_after THEN Earned_to_date
         ELSE month_after
      END AS EndRiskMonth
  ,   DateDiff(day, PolicyEffectiveDate, PolicyExpirationDate) AS policy_days
  ,   WrittenPremium
      FROM policy_data
      JOIN calendar
          ON (policy_data.PolicyEffectiveDate &lt; calendar.month_after
          AND calendar.month_of &lt; policy_data.PolicyExpirationDate)
      CROSS JOIN Earned_to_date
      WHERE  month_of &lt; Earned_to_date
  )
  SELECT      PolicyNumber,
              --ClassCode,
              Year(StartRiskMonth) as YearStartRisk, 
              Month(StartRiskMonth) as MonthStartRisk,
              c.YearNum,c.MonthNum,
              convert(varchar(7), StartRiskMonth, 120) as RiskMonth,
              sum(WrittenPremium * DateDiff(day, StartRiskMonth, EndRiskMonth) / policy_days) as EarnedPremium
  FROM        tblCalendar  c
  LEFT  JOIN policy_dates l ON c.YearNum=Year(l.StartRiskMonth) and c.MonthNum = Month(l.StartRiskMonth) AND l.StartRiskMonth BETWEEN '01-01-2012' AND  '10-31-2016'
  WHERE c.YearNum Not IN (2017) --and PolicyNumber = 'PACA1000191-00'
  GROUP BY    convert(varchar(7), StartRiskMonth, 120),
              Year(StartRiskMonth) , Month(StartRiskMonth),
              c.YearNum,c.MonthNum,PolicyNumber
  ORDER BY    PolicyNumber,c.YearNum,c.MonthNum
  DROP TABLE #PolicyNumbers
  </code></pre>
  <p>I am using the split function that works fine:</p>
  <pre><code>ALTER FUNCTION [dbo].[StringOfStringsToTable]
      (
          @Strings varchar(8000),
          @Separator char(1)
      )
  RETURNS @StringTable table (String varchar(500))
  AS
      BEGIN
  
          DECLARE @String varchar(500), @Pos int
  
          SET @Strings = LTRIM(RTRIM(@Strings))+ @Separator
          SET @Pos = CHARINDEX(@Separator, @Strings, 1)
  
              WHILE @Pos &gt; 0
              BEGIN
                  SET @String = LTRIM(RTRIM(LEFT(@Strings, @Pos - 1)))
  
                  IF @String &lt;&gt; '' INSERT INTO @StringTable VALUES (@String)
  
                  SET @Strings = RIGHT(@Strings, LEN(@Strings) - @Pos)
                  SET @Pos = CHARINDEX(@Separator, @Strings, 1)
              END
  
      RETURN
      END
      
  </code></pre>
  <p>This is the result set in SSMS:
  <a href="https://i.stack.imgur.com/z329g.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/z329g.png" alt="enter image description here" /></a></p>
  <p>And there is an error:</p>
  <p><a href="https://i.stack.imgur.com/GQDhu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GQDhu.png" alt="enter image description here" /></a></p>
  <p>In a query designer in SSRS if I declare variable at the top with multiple value parameter than it works.</p>
  <pre><code>DECLARE @ClassCode varchar(100) = '31439,739889,33528,40199,21289,40427,42594,5283,5251,34489' 
  </code></pre>
  <p><a href="https://i.stack.imgur.com/QJqQh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QJqQh.png" alt="enter image description here" /></a></p>
  <p>But if I take off that statement than I receive the same error.
  What is going on here?</p>