0

I've created a test table, then a Type Table and then a SP:

CREATE TABLE prueba (

    id int IDENTITY,
    datos varchar (20),
    nums NUMERIC (10,2)
    CONSTRAINT PK_PRUEBA PRIMARY KEY (id)
)

CREATE TYPE dbo.pruebatable AS TABLE (

    datos varchar (20),
    nums NUMERIC (10,2)
)

CREATE PROC spruebatable
@test pruebatable READONLY
AS
BEGIN
INSERT INTO prueba (datos,nums)
SELECT 
datos, nums
FROM @test

END;

And in python, I'm trying to calls this with a private connection function that works fine:

from haegpi import sqlconn

cursor = sqlconn()

var = ('int',1)
sql = "{CALL spruebatable (?)}"
cursor.execute (sql,var)

I've tried to send it as tuple, list and result is the same. Any clues?

Thom A
  • 88,727
  • 11
  • 45
  • 75
  • 2
    Try `var = [('int',1)]` – Gord Thompson Apr 26 '23 at 13:35
  • Hi there Gord! I've tried that but i receive this current error : "pyodbc.Error: ('HY004', '[HY004] [Microsoft][ODBC SQL Server Driver]Tipo de datos SQL no válido (0) (SQLBindParameter)')" – Juan Pablo Humani Apr 26 '23 at 13:58
  • Hmm, okay … try `var = ([('int', 1)],)` – Gord Thompson Apr 26 '23 at 14:32
  • Thanks Gordon, but same same: "pyodbc.Error: ('HY004', '[HY004] [Microsoft][ODBC SQL Server Driver]Tipo de datos SQL no válido (0) (SQLBindParameter)')" I still cant find the solution. – Juan Pablo Humani Apr 26 '23 at 15:02
  • It appears that you are using the ancient `Driver=SQL Server` ODBC driver. Your problem should go away if you install `ODBC Driver 17 for SQL Server` and use that instead. – Gord Thompson Apr 26 '23 at 15:28
  • Gordon, i've checked and in my client computer ODBC driver is from 2023. – Juan Pablo Humani Apr 26 '23 at 15:54
  • 1
    `print(connection.getinfo(pyodbc.SQL_DRIVER_NAME))`. If it shows `SQLSRV32.DLL` then you are using the ancient driver regardless of the date stamp on the DLL file. – Gord Thompson Apr 26 '23 at 15:58
  • Ok Gordon. now i've managed to get something everytime i do: var = ([('int', 1)],) but i cant solve how to use it. Imagine we have this simple function: def var_prueba(): mla = 'MLA12345678' price = 120 return mla, price How should i call it to make it work like you did var = ([('int', 1)],)? – Juan Pablo Humani Apr 26 '23 at 16:50

0 Answers0