AlliDeacon AlliDeacon - 1 year ago 89
SQL Question

Data Conversion using pyodbc to query iSeries database - Conversion error

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:

#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]'"""
row = cursor.fetchall()
if row :

print ("Today : " + today)

Answer Source

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.

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.

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


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download