none
How to convert float to int ? RRS feed

  • Question

  • HI, as below is my result and SQL script , May i know how to convert my DSB result to int ? Please advise, thank you.

    Select distinct A.INV_ID,A.INV_TYPE,A.INV_SHORTDESC,A.INV_ROL ,sum(B.INV_QTY) as TOTALQTY,
    Case When A.INV_USAGE = 0
                    Then 0            
                    Else (b.INV_QTY) / a.INV_USAGE
                              
                    End As DSB

    from OTH_INV_DETAILS A join OTH_INV_QTY_LOC B  ON A.INV_ID= B.INV_ID
    where 1=1
    or
    B.INV_QTY <= A.INV_ROL
    group by A.INV_ID,A.INV_TYPE,A.INV_SHORTDESC,A.INV_ROL,B.INV_QTY,A.INV_USAGE,b.INV_LOCATION

    Friday, June 22, 2012 9:44 AM

Answers

  • Hi,

    You should use CAST()

    Select distinct A.INV_ID,A.INV_TYPE,A.INV_SHORTDESC,A.INV_ROL ,sum(B.INV_QTY) as TOTALQTY,
    Case When A.INV_USAGE = 0
                    Then 0            
                    Else CAST((b.INV_QTY) / a.INV_USAGE AS int)
                              
                    End As DSB
    
    from OTH_INV_DETAILS A join OTH_INV_QTY_LOC B  ON A.INV_ID= B.INV_ID
    where 1=1
    or
    B.INV_QTY <= A.INV_ROL
    group by A.INV_ID,A.INV_TYPE,A.INV_SHORTDESC,A.INV_ROL,B.INV_QTY,A.INV_USAGE,b.INV_LOCATION

    • Marked as answer by Caulson Monday, June 25, 2012 1:29 AM
    Friday, June 22, 2012 9:51 AM
  • Hello,

    This question is not related to .Net Base Class Library but more surely to Transact-SQL.

    Please, is it possible for a moderator to move this thread towards the Transact-SQL forum ?

    http://social.msdn.microsoft.com/Forums/en-US/transactsql/threads

    Thanks beforehand

    Have a nice day


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.

    • Marked as answer by Caulson Monday, June 25, 2012 1:29 AM
    Friday, June 22, 2012 5:29 PM

All replies

  • Hi,

    You should use CAST()

    Select distinct A.INV_ID,A.INV_TYPE,A.INV_SHORTDESC,A.INV_ROL ,sum(B.INV_QTY) as TOTALQTY,
    Case When A.INV_USAGE = 0
                    Then 0            
                    Else CAST((b.INV_QTY) / a.INV_USAGE AS int)
                              
                    End As DSB
    
    from OTH_INV_DETAILS A join OTH_INV_QTY_LOC B  ON A.INV_ID= B.INV_ID
    where 1=1
    or
    B.INV_QTY <= A.INV_ROL
    group by A.INV_ID,A.INV_TYPE,A.INV_SHORTDESC,A.INV_ROL,B.INV_QTY,A.INV_USAGE,b.INV_LOCATION

    • Marked as answer by Caulson Monday, June 25, 2012 1:29 AM
    Friday, June 22, 2012 9:51 AM
  • Hello,

    This question is not related to .Net Base Class Library but more surely to Transact-SQL.

    Please, is it possible for a moderator to move this thread towards the Transact-SQL forum ?

    http://social.msdn.microsoft.com/Forums/en-US/transactsql/threads

    Thanks beforehand

    Have a nice day


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.

    • Marked as answer by Caulson Monday, June 25, 2012 1:29 AM
    Friday, June 22, 2012 5:29 PM