Home > database >  quotations: A syntax error has occurred. SQLCODE=-201
quotations: A syntax error has occurred. SQLCODE=-201

Time:10-14

I am trying to do something like this:

query = (
"select mandant,posnr,"
"lieferbedingung,nrkreis_nr"
"from eakopf_t where posnr[10,10] = \" \" , and posnr[1,2] not in (\"99\",\"RE\",\"UB\")"
"and mandant <> 999;"
)

queryset  = [(query, filename)]



df = pd.read_sql(query, engine.connect())

but I get this error:

SQLNumResultCols failed: [IBM][CLI Driver][IDS/UNIX64] A syntax error has occurred. SQLCODE=-201

I guess its becuase of the quotation marks but i'm not sure how to modify it. I already tried without backslash too

[SQL: select mandant,posnr,systemdat,fk_kto_auf,fk_kto_not1,fk_kto_not2,fk_kto_empf,fk_kto_adr5,fk_kto_adr6,fk_kto_adr7,fk_kto_adr8,fk_kto_adr9,adr_auftraggeber,anzahl_kolli,volumen,gewicht,lieferbedingung,aufdat,ankdat,versandort,modus,ladehafen,loeschhafen,bereich,nrkreis_nr from eakopf_t where posnr[10,10] = " " , and posnr[1,2] not in ("99","RE","UB") and mandant <> 999;]

CodePudding user response:

You have:

query = (
"select mandant,posnr,"
"lieferbedingung,nrkreis_nr"
"from eakopf_t where posnr[10,10] = \" \" , and posnr[1,2] not in (\"99\",\"RE\",\"UB\")"
"and mandant <> 999;"
)

There is no space separating nrkreis_nr from from, so the printed query would contain:

select mandant,posnr,lieferbedingung,nrkreis_nrfrom eakopf_t where

It's probably best to put spaces at the start (or the end) of each continuation line:

query = (
"select mandant, posnr,"
" lieferbedingung, nrkreis_nr"
" from eakopf_t where posnr[10,10] = \" \" and posnr[1,2] not in (\"99\",\"RE\",\"UB\")"
" and mandant <> 999;"
)

It's not necessary when there is a punctuation character at the end of one line or the beginning of the next (so the comma at the end of the first line of the string means the space at the start of the next line is not mandatory), but it is safest.

I also removed a stray comma and space in:

"from eakopf_t where posnr[10,10] = \" \" , and posnr[1,2] not in (\"99\",\"RE\",\"UB\")"
  • Related