title: SQLServerException: The conversion from UNKNOWN to UNKNOWN is unsupported using Groovy
body: <p>I am trying to run a query using Groovy SQL against a SQL Server DB. However, I am receiving the following exception: <code>com.microsoft.sqlserver.jdbc.SQLServerException: The conversion from UNKNOWN to UNKNOWN is unsupported</code></p>
  
  <pre><code>Grails version: 2.2.5
  SQL Server version: 9.0
  </code></pre>
  
  <p><strong>The script I am running from the Grails console:</strong></p>
  
  <pre><code>import groovy.sql.*
  
  Sql sql = Sql.newInstance(ctx.dataSource_sqlserver)
  
  def query = '''
      select
          avg(cast(score as decimal)) average_score
      from
          StudentQuestionScores
      where
          id in ( :ids )
          and question = :question
  '''
  
  def ids = Student.list().collect { it.id }  // Succeeds
  def row = sql.firstRow(query, [ids: ids, question: 'Insert Question Here']) // ERROR
  
  sql.close()
  
  println row.average_score // Never makes it here :(
  </code></pre>
  
  <p>Does anyone know why this might be or how I can fix it? Thank you!</p>
  
  <p><strong>Stacktrace:</strong></p>
  
  <pre><code>com.microsoft.sqlserver.jdbc.SQLServerException: The conversion from UNKNOWN to UNKNOWN is unsupported.
      at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
      at com.microsoft.sqlserver.jdbc.DataTypes.throwConversionError(DataTypes.java:1117)
      at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setObject(SQLServerPreparedStatement.java:991)
      at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setObjectNoType(SQLServerPreparedStatement.java:926)
      at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setObject(SQLServerPreparedStatement.java:935)
      at org.apache.commons.dbcp.DelegatingPreparedStatement.setObject(DelegatingPreparedStatement.java:169)
      at org.apache.commons.dbcp.DelegatingPreparedStatement.setObject(DelegatingPreparedStatement.java:169)
      at groovy.sql.Sql.setObject(Sql.java:3649)
      at groovy.sql.Sql.setParameters(Sql.java:3614)
      at groovy.sql.Sql.getPreparedStatement(Sql.java:3875)
      at groovy.sql.Sql.getPreparedStatement(Sql.java:3922)
      at groovy.sql.Sql.access$900(Sql.java:227)
      at groovy.sql.Sql$PreparedQueryCommand.runQuery(Sql.java:4078)
      at groovy.sql.Sql$AbstractQueryCommand.execute(Sql.java:4027)
      at groovy.sql.Sql.rows(Sql.java:1945)
      at groovy.sql.Sql.rows(Sql.java:1835)
      at groovy.sql.Sql.rows(Sql.java:1816)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  </code></pre>