-1

I am calling a karate DButil to execute one of the database query in the karate script:

 * def test = db.readValue('SELECT * FROM CLIENT C WHERE C.ClientCode = ' + globalAccountID)

Here i', unable to convert the globalAccountID to string. Please help on this.

My error trace is below:

javascript evaluation failed: db.readRows('SELECT * FROM CLIENT C WHERE C.ClientCode = ' + globalAccountID), StatementCallback; uncategorized SQLException for SQL [SELECT * FROM CLIENT C WHERE C.ClientCode = 707]; SQL state [S0001]; error code [245]; Conversion failed when converting the varchar value 'YTLQVLBK' to data type int.; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: Conversion failed when converting the varchar value 'YTLQVLBK' to data type int.

Alex
  • 4,885
  • 3
  • 19
  • 39
  • please don't ask questions about databases with the karate tag, this is NOT related to Karate. please read this: https://stackoverflow.com/a/52078427/143475 – Peter Thomas Sep 13 '19 at 03:10

1 Answers1

0

The issue is in this code:

C.ClientCode = 707

More specifically, you are comparing an integer to a string. Based on SQL Server Data type precedence rules, it means that column C.ClientCode is converted to integer before comparison can take place.

The solution is to convert 707 to string (varchar) type. You can do something like this:

'SELECT * FROM CLIENT C WHERE C.ClientCode = ''' + globalAccountID + ''''
Alex
  • 4,885
  • 3
  • 19
  • 39