MSSQL expected TextLiteral in Stored Procedure

Hi, I’m try to use a stored procedure in a method, it takes the parameters idfac As integer and opc As String:

sql= "mant_fun " + idfac + ", " + opc "
The stored procedure it’s the same, needs an Integer and a String, but the error that xojo sends me it’s:

[quote]Window1.asd1, line 7
Type mismatch error. Expected TextLiteral, but got Integer
sql= "mant_fun " + idfac + ", " + opc "[/quote]

idfac must be an Integer, if I put in the string sql: Str(idfac) like this:

sql= "mant_fun " + Str(idfac) + ", " + opc "
The error doesn’t appears, but obviously because idfac needs an Integer and I’m sending a String, the error says: Error converting data type nvarchar to int.
How can I fix this? How Can I make possible to the string sql to accept an Integer and why it wants TextLiteral?

When you create a string with an integer you need to convert it to string.
When you pass a string to sql you must embed it in single quote.

sql= “mant_fun “+Str(idfac)+”, '”+opc+"’"

so if idfac is 1 and opt is A you get: mant_fun 1, ‘A’

[quote=368250:@Antonio Rinaldi]When you create a string with an integer you need to convert it to string.
When you pass a string to sql you must embed it in single quote.

sql= “mant_fun “+Str(idfac)+”, '”+opc+"’"

so if idfac is 1 and opt is A you get: mant_fun 1, ‘A’[/quote]
Wow I didn’t really knew that, it helped me to understand it more, thanks.
But the problem it’s that idfac must be an integer for my table, it’s the “identifier”
like:
Create table TTable (idfac int, opc nvarchar)
When I put str(idfac) in my method, it converts the idface from an Integer to a string and xojo let me execute the app, but because idfac it’s an integer in the table then the problem appears because I’m sending a String. So I think that I really need that idfac stays as an Integer, but Xojo expects TextLiteral and I don’t understand that :sadface:

It’s funny, actually sending a String it’s correct, because in my table opc was an integer, not a String
(Xojo was refering to opc not idfac). So I didn’t really needed to pass idfac As integer, that was not the problem, it’s okay to send it as Str(idfac). Thank you so much for your help :D!

the db engine when receive the command (the string you create) interprets (for parameters) as string only what’s between single quote so in my sample 1 is a integer and ‘A’ is a string