Menu

money field truncated

2008-01-24
2013-04-29
  • Evren Esat Özkan

    Hi,

    I'm querying a table that contains a money field with 4 decimal places. but when I fetch the data, they become to Decimal data type with 2 decimal places;

    In [4]: b.execute("select lfiyat from tbstokfiyati where lfiyat=0.0428")
    In [5]: b.fetchall()
    Out[5]: [(Decimal("0.04"),)]

    How can I get the correct value?

    Thanks,

     
    • Evren Esat Özkan

      Tried with lower level adapter with converting money field to varchar but that doesn't worked too;

      In [11]: mssql=_mssql.connect(...)

      In [13]: mssql.query("select cast(lfiyat as varchar(30))  from tbstokfiyati where lfiyat=0.0428")
      Out[13]: 1

      In [14]: mssql.fetch_array()
      Out[14]: [((('', 1),), 1, [('0.04',)])]

      Is this problem could be related with the db server?

      Thanks

       
    • Evren Esat Özkan

      Ok, I found the problem was not realted with pymssql and I solved it with different CAST command;

      select ... CAST(lfiyat AS decimal(10,4)) from ...

      But I still don't know why I need to do this to get the real value.

       

Log in to post a comment.