multiple convert decimal commands

  • Hi,

    Can someone explain me what this particular statement does. Here there are 3 convert statements, and I couldn't able to understand purpose of it. Please explain me. Thank you.

    Totalavg = CONVERT(DECIMAL(7,5), CONVERT(DECIMAL(10,5), SUM(PhoneNbr1 + PhoneNbr2 + PhoneNbr3)) / CONVERT(DECIMAL(11,5), COUNT(*)))

  • Not knowing your system, it really is hard to say what it is doing or why.

  • My guess is that they are trying to get a specific answer - to 5 decimal places rather than none. If you can, run the original way and run it, stripping out the CONVERTs, and compare them.

    Hi Lynn, I'm glad to hear you found work closer to home. Driving up here every day must have been tiring and expensive.

    The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge. - Stephen Hawking

  • The datatype for Totalavg is 'Decimal' of prec 9 and scale 5. This I am using on a select statement. I just need is explanation of why multiple decimal statements are used. Let me know if you need more info. Thank you

  • mtillman-921105 (3/6/2012)


    My guess is that they are trying to get a specific answer - to 5 decimal places rather than none. If you can, run the original way and run it, stripping out the CONVERTs, and compare them.

    Hi Lynn, I'm glad to hear you found work closer to home. Driving up here every day must have been tiring and expensive.

    Drove to Denver for fifteen years, not really a problem. Starting again seven years later and it was just kicking my *** physically.

    Haven't really started doing any real work here yet, but I really like it so far.

  • Without any ddl or data it is hard to say...but just reading it at face value calculating the average phone number is hysterically funny. 😛

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • CONVERT(DECIMAL(9,5), --Executes 3RD

    CONVERT(DECIMAL(18,5), SUM(PH1 + PH2 + PH3)) / - - Executes 1st

    CONVERT(DECIMAL(18,5), COUNT(*)) -- Executes 2nd

    )

    ABOVE mentioned steps it usually follows, This is what i guess. correct me, if anything wrong.

  • Lynn Pettis (3/6/2012)


    Drove to Denver for fifteen years, not really a problem. Starting again seven years later and it was just kicking my *** physically.

    Haven't really started doing any real work here yet, but I really like it so far.

    I know that I sure wouldn't want to make that drive every weekday. It's at least an hour each way on a good day. We wound up here from the Springs since Denver has plenty of jobs available.

    The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge. - Stephen Hawking

  • mtillman-921105 (3/6/2012)


    Lynn Pettis (3/6/2012)


    Drove to Denver for fifteen years, not really a problem. Starting again seven years later and it was just kicking my *** physically.

    Haven't really started doing any real work here yet, but I really like it so far.

    I know that I sure wouldn't want to make that drive every weekday. It's at least an hour each way on a good day. We wound up here from the Springs since Denver has plenty of jobs available.

    Yea, about 70 - 75 minutes from south side of Springs to Meridian on a good day. Commute now is about 20 minutes. There are jobs down here, just hard to find them at times. There does appear to be more up there but I want to be near my kids. Middle one graduates this year and will be going to ERAU. The youngest starts high school next school year.

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply