title: Error in loop. ('The SQL contains 1 parameter markers, but 4 parameters were supplied', 'HY000')
body: <p>I have an issue with a loop. I have a loop as follows:</p>
  
  <pre><code>for i in theList:
  
      temp=process_query('SELECT FName, LName FROM Employee WHERE SSN=?', i)
      known_hours=process_query('SELECT DISTINCT SUM(Coalesce(Hours,0)) FROM Works_On WHERE ESSN=?',(i))
  </code></pre>
  
  <p>where <code>theList</code> is defined as:</p>
  
  <pre><code>theList=process_query('SELECT DISTINCT SSN FROM Employee', None)
  </code></pre>
  
  <p>This now works without error, finally thanks to beargle. However I have found another issue that I cannot fix, namely that when I call the process_query function below:</p>
  
  <pre><code>def process_query(query, parameters):    
      if(parameters is None):    
          cursor1.execute(query)
      else:
          cursor1.execute(query, parameters)    (*LINE 33)
  
      n=0
      lista = []
  
      while 1:
          row = cursor1.fetchone()    
          if not row:
              break
          lista.append(row[0])
          n = n+1
      return lista    
  </code></pre>
  
  <p>The trouble now is that the program complains at the second cursor1.execute (marked with a asterix, *) that ('The SQL contains 1 parameter markers, but 4 parameters were supplied', 'HY000') which I believe stems from that <code>i</code> is a social security number and thus is not a single digit integer, but I cannot understand how to fix this issue. </p>
  
  <p>edit: Here comes the whole loop with the whole print:</p>
  
  <p>the loop (and some definitions)</p>
  
  <pre><code>theList=process_query('SELECT DISTINCT SSN FROM Employee', None)    
  temp=[]
  
  for i in theList:
      temp=process_query('SELECT FName, LName FROM Employee WHERE SSN= ?', (i))   (LINE 71)    
      known_hours=process_query('SELECT DISTINCT SUM(Coalesce(Hours,0)) FROM Works_On WHERE ESSN=?',(i))    
      temp.append(known_hours)    
      unknown_hours=process_query('SELECT Distinct COUNT(*) FROM Works_On WHERE ISNULL(Hours) AND ESSN=?', (i))    
      unknown_hours=map(int,unknown_hours)    
      temp.append(unknown_hours)    
      if(unknown_hours &gt; 0):    
          temp.append('Yes')    
      else:    
          temp.append('No')    
      theList.append(temp)        
  print theList
  </code></pre>
  
  <p>which gives the following print (NOTE! Ive also updated process_query so it prints out query and parameters (in that order). </p>
  
  <pre><code>SELECT DISTINCT SSN FROM Employee
  
  None
  SELECT FName, LName FROM Employee WHERE SSN= ?
  
  123456789
  
  SELECT DISTINCT SUM(Coalesce(Hours,0)) FROM Works_On WHERE ESSN=?
  
  123456789
  
  SELECT Distinct COUNT(*) FROM Works_On WHERE ISNULL(Hours) AND ESSN=?
  
  123456789
  
  SELECT FName, LName FROM Employee WHERE SSN= ?
  
  333445555
  
  SELECT DISTINCT SUM(Coalesce(Hours,0)) FROM Works_On WHERE ESSN=?
  
  333445555
  
  SELECT Distinct COUNT(*) FROM Works_On WHERE ISNULL(Hours) AND ESSN=?
  
  333445555
  
  SELECT FName, LName FROM Employee WHERE SSN= ?
  
  453453453
  
  SELECT DISTINCT SUM(Coalesce(Hours,0)) FROM Works_On WHERE ESSN=?
  
  453453453
  
  SELECT Distinct COUNT(*) FROM Works_On WHERE ISNULL(Hours) AND ESSN=?
  
  453453453
  
  SELECT FName, LName FROM Employee WHERE SSN= ?
  
  666884444
  
  SELECT DISTINCT SUM(Coalesce(Hours,0)) FROM Works_On WHERE ESSN=?
  
  666884444
  
  SELECT Distinct COUNT(*) FROM Works_On WHERE ISNULL(Hours) AND ESSN=?
  
  666884444
  
  SELECT FName, LName FROM Employee WHERE SSN= ?
  
  888665555
  
  SELECT DISTINCT SUM(Coalesce(Hours,0)) FROM Works_On WHERE ESSN=?
  
  888665555
  
  SELECT Distinct COUNT(*) FROM Works_On WHERE ISNULL(Hours) AND ESSN=?
  
  888665555
  
  SELECT FName, LName FROM Employee WHERE SSN= ?
  
  987654321
  
  SELECT DISTINCT SUM(Coalesce(Hours,0)) FROM Works_On WHERE ESSN=?
  
  987654321
  
  SELECT Distinct COUNT(*) FROM Works_On WHERE ISNULL(Hours) AND ESSN=?
  
  987654321
  
  SELECT FName, LName FROM Employee WHERE SSN= ?
  
  987987987
  
  SELECT DISTINCT SUM(Coalesce(Hours,0)) FROM Works_On WHERE ESSN=?
  
  987987987
  
  SELECT Distinct COUNT(*) FROM Works_On WHERE ISNULL(Hours) AND ESSN=?
  
  987987987
  
  SELECT FName, LName FROM Employee WHERE SSN= ?
  
  999887777
  
  SELECT DISTINCT SUM(Coalesce(Hours,0)) FROM Works_On WHERE ESSN=?
  
  999887777
  
  SELECT Distinct COUNT(*) FROM Works_On WHERE ISNULL(Hours) AND ESSN=?
  
  999887777
  
  SELECT FName, LName FROM Employee WHERE SSN= ?
  
  ['John', [Decimal('40.0')], [0], 'Yes']
  
  Traceback (most recent call last):
    File "sumrpt2.py", line 72, in &lt;module&gt;
      temp=process_query('SELECT FName, LName FROM Employee WHERE SSN= ?', (i))
    File "sumrpt2.py", line 35, in process_query
      cursor1.execute(query, parameters)
  pyodbc.ProgrammingError: ('The SQL contains 1 parameter markers, but 4 parameters were supplied', 'HY000')
  </code></pre>
  
  <p>Anyone have a clue?</p>
  
  <p>Regards,
  Cenderze</p>