sqlteradata

How do I fix this in my SQL, it has a problem with character type: ' ', in my first one for metro it doesn't return


cod_cli = df\['cod_cli'\].tolist()

cod_cli_str = ','.join(map(str, cod_cli))

\# clientesAtacado =

query = f"""

select \* from P_VTVVIEDB.VBRA_CITY

where bracityid in (select bracityid

from P_VTVVIEDB.VSW_ADDRESS

where swobjectid in (select swsiteid from P_VTVVIEDB.VSW_SITE where swcustomerid in

(SELECT swcustomerid FROM P_VTVVIEDB.VSW_CUSTOMER WHERE CONCAT('40',left(TELCNPJ,8)) IN (${cod_cli_str}))))

;

my return the query it's this:

Bad character in format or data of SW_CUSTOMER.TELCNPJ.
 at gosqldriver/teradatasql.formatError ErrorUtil.go:85

Solution

  • # assume cod_cli as list of strings
    cod_cli_str = ','.join(f"'{item}'" for item in cod_cli) #format each item as string literal
    
    query = f"""
    select * from P_VTVVIEDB.VBRA_CITY
    where bracityid in (
        select bracityid
        from P_VTVVIEDB.VSW_ADDRESS
        where swobjectid in (
            select swsiteid 
            from P_VTVVIEDB.VSW_SITE 
            where swcustomerid in (
                SELECT swcustomerid 
                FROM P_VTVVIEDB.VSW_CUSTOMER 
                WHERE CONCAT('40', left(TRIM(TELCNPJ), 8)) IN (${cod_cli_str})
            )
        )
    );