CAST or CONVERT: invalid attributes specified for type 'float'

Posted on 2008-11-17
Last Modified: 2012-05-05
When I run this code snippet:

select sum(cast(duration as float (2,2))/60)
                        from [].cdr.dbo.CallDetailRecord

I get the error in the thread title. This started happening after we upgraded to SQL 2005. Easy fix I am sure, just not quite sure of the new syntax
Question by:CSTX_Analysts
    LVL 9

    Assisted Solution

    error on float(2,2)
    you could do decimai(2,2) or numeric(2,2)

    select sum(cast(duration as float)/60)
                            from [].cdr.dbo.CallDetailRecord

    Open in new window


    Author Comment

    That is actually what I thought about doing. I just wanted to make sure there were no hidden "gotchas" going from using float to using decimal. From what I can tell the results are the same.

    Author Comment

    Ok I have done the following. I ran the old code on a SQL2000 server. I also ran the code on a SQL2005 server , replacing "Float" with "Decimal". The result that is returned is slightly different between the two. I spoke with the original developer and they said that they used "Float" because it returned the most exact results so........ The question is can we make the returns from using "Decimal" or can I code it so that "Float" will still work?
    LVL 9

    Expert Comment


    Floating precision number data from: float [ ( n ) ] Floating point data is approximate
    - 1.79E+308 to -2.23E-308, 0 and 2.23E-308 to 1.79E+308 depends on the value of n
    Please  understand the rounding errors with FLOAT([n]) and the storage size for your needs (n 1-24 = 7 digits =4 bytes, n 25-53 =15 digits = 8 bytes) depending on [n], but if the developers are using Float probably make sence use float for you n value Precision Storage size. The synonym for double precision for developers is float(53).
    For decimal and  numeric: Functionally equivalent:
    decimal Fixed precision and scale numeric data from -10^38 +1 through 10^38 -1 numeric Fixed precision and scale numeric data from -10^38 +1 through 10^38 -1  


    Accepted Solution

    I ran the query using "Float" instead of "Float (2,2). Compared the results between the two versions and they were the same.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
    For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
    Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now