如何在我的 SQL 中修复此问题,它有字符类型问题:“ ”,在我的第一个 Metro 中它不返回

问题描述 投票:0回答:1
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}))))

;

我返回的查询是这样的:

Bad character in format or data of SW_CUSTOMER.TELCNPJ.
 at gosqldriver/teradatasql.formatError ErrorUtil.go:85
sql teradata
1个回答
0
投票
# 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})
        )
    )
);

  • 确保
    TELCNPJ
    是字符串或转换/转换为字符串
  • CONCAT('40', left(TELCNPJ, 8))
    结果必须与
    cod_cli_str
  • 中的值格式匹配
  • 调整查询以将每个项目包装在 '' 中,以确保 SQL 将它们作为字符串处理
  • 使用
    TRIM
    删除意外的空白[您可以选择处理更多意外的值]
© www.soinside.com 2019 - 2024. All rights reserved.