Sql result is not same in python & HANA

SELECT distinct STG.*,‘D’ as FLAG FROM test STG left join
(
select distinct * from test1 b
where b.acc = “”" + str(f"{inbody[‘id’]:0>10}“) + “'” + “””
)
Original on Original.acc= STG.acc
where Original.acc is null

in HANA i am getting one record but unfortunately in python i am getting 2 records

I couldn’t begin to comment in a meaningful way on your question. I will offer a couple hints though.

  • You posted SQL code, not Python code which uses SQL. If your problem is actually in your Python code, nobody can tell.
  • What’s HANA? (I wrote a fair amount of Python code which makes SQL queries in my day, but never encountered that tool/term/system.)

Cheers…

Skip

Rewrite your code using a proper parameterized query (instead of leaving yourself vulnerable to SQL injection) and see if your issue also disappears.

I think from the:

 """ + str(f"{inbody['id']:0>10}") + "'" + """

in the middle that it is a copy/paste of part of a multiline Python
string expression.

Kishore, you might do better to (a) show the surrounding code and (b)
actually print() the resulting piece of SQL you’re generating, and
show us that too. Maybe it isn’t making the query you thought it was.

Also, when pasting in code, put it between triple backticks to preserve
the formatting, eg:

 ```
 your code
 or example output
 goes here
 ```

Cheers,
Cameron Simpson cs@cskk.id.au