title: Comparing two tables using groovy script in soapui
body: <p>I need to compare the values of 2 tables in SQL Server. I have created script but the script I've made is only comparing the whole table as one. The one I needed is comparing each row of 2 tables. Here is my script I've made</p>
  
  <pre><code>import groovy.sql.Sql
  import java.sql.ResultSet
  import com.eviware.soapui.support.GroovyUtils
  import groovy.sql.DataSet
  
  def sql = Sql.newInstance("jdbc:sqlserver://MSSQLSERVER01:1433",
              "User", "password", "com.microsoft.sqlserver.jdbc.SQLServerDriver")
  
  resultsA = sql.eachRow("SELECT * FROM Bikestores.production.brands"){
  temp1=it.toRowResult().values().join(", ") 
  }
  resultsB = sql.eachRow("SELECT * FROM Bikestores.dbo.sample"){
  temp2=it.toRowResult().values().join(", ") 
  }
  
  while(temp1 != null &amp;&amp; temp2 != null){
  
  brandA = temp1
  brandB = temp2
  
  if(brandA==brandB){
      log.info "True"
      break
  }
  
  else{
     log.info "False"
     break
  } 
  } 
  sql.close()
  </code></pre>
  
  <p>The result of this is False since there is a difference in values. 
  I need to compare each row, like I will get 9 results since I have a 9 rows. If you have better scripts please let me know. Thank you. </p>
  
  <p>Edit: </p>
  
  <pre><code>Sample data 
  
  Table 1
  
  id|name | check  
  1  | abc   | yes  
  2  | def   | yes  
  3  | ghi  | yes  
  4  | jkl  | yes  
  
  Table 2  
  
  id|name | check  
  1  | abc   | yes  
  2  | def   | yes  
  3  | pqr  | yes  
  4  | mno  | yes  
  
  
  Expected Result  
  [table1_name][table2_name]: true  
  [table1_name][table2_name]: true  
  [table1_name][table2_name]: false  
  [table1_name][table2_name]: false  
  </code></pre>