使用pyodbc查询iSeries数据库的数据转换 - 转换错误

时间:2022-08-10 16:56:13

I am trying to filter records based on a Zoned Decimal value that is returning as Decimal(160919, ). How can I use this to filter against a date (ie: 160919) Below is the code that I'm using to extract the order data:

我试图根据返回为Decimal(160919,)的Zoned Decimal值过滤记录。如何使用它来过滤日期(即:160919)以下是我用来提取订单数据的代码:

#connect to APlus
import pyodbc
import time
import cursor as cursor


today = int(time.strftime("%y%m%d"))
whatisit = type(today)
print whatisit
cnxn = pyodbc.connect('DSN=aplus; uid=username;pwd=password')
cursor = cnxn.cursor()
query = """ select OHORNO, OHRSDT
            from ORHED
            where OHCSNO = 206576  and CAST(OHRSDT AS INT) = '$[today]'"""
cursor.execute(query)
row = cursor.fetchall()
if row :
    print(row)

print ("Today : " + today)

1 个解决方案

#1


0  

There ended up being a space at the end of the date in the record. I used Left(OHEXDT, 6) to compare and everything is working as expected.

最终在记录结束时成为了一个空格。我使用Left(OHEXDT,6)进行比较,一切都按预期工作。

This actually only worked for an isolated occurrence, and then failed.

这实际上只适用于孤立的事件,然后失败。

I am now using substring to pull out the numbers in the format I need to compare them to.

我现在使用substring以我需要比较它们的格式提取数字。

where OHCSNO = 206576 and integer(substr(OHESDT,1,6)) = '160926'

其中OHCSNO = 206576和整数(substr(OHESDT,1,6))='160926'

Thanks!

谢谢!

#1


0  

There ended up being a space at the end of the date in the record. I used Left(OHEXDT, 6) to compare and everything is working as expected.

最终在记录结束时成为了一个空格。我使用Left(OHEXDT,6)进行比较,一切都按预期工作。

This actually only worked for an isolated occurrence, and then failed.

这实际上只适用于孤立的事件,然后失败。

I am now using substring to pull out the numbers in the format I need to compare them to.

我现在使用substring以我需要比较它们的格式提取数字。

where OHCSNO = 206576 and integer(substr(OHESDT,1,6)) = '160926'

其中OHCSNO = 206576和整数(substr(OHESDT,1,6))='160926'

Thanks!

谢谢!