Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2005
    Posts
    266

    Unanswered: CAST and ROUND (MS SQL 2005)

    for MS SQL 2005 I am having



    SELECT name.Name
    , Percentage = (count(*) / ((SELECT tot = COUNT(*) * 1.0 ) FROM dbo.Name)) * 100)
    FROM dbo.Name
    GROUP BY Name


    how can i CAST and ROUND (count(*) / ((SELECT tot = COUNT(*) * 1.0 ) FROM dbo.Name)) * 100) ?

    then ROUND (the result, 2) ?

    CAST(count(*) / ((SELECT tot = COUNT(*) * 1.0 ) FROM dbo.Name)) * 100) AS DOUBLE does not work

    thank you for helping

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Blimey. Can you remove the unnecessary brackets? There is defo one missing in your last one. There is no Double in SQL Server. Why are you not using Round and using Cast? Why not leave this to the front end to handle? What does "does not work" mean?
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    ... and totty.tot in my last bit of help is more efficient (logically anyway - unless SQL Server figures out what you are doing and optimises the query).
    Testimonial:
    pootle flump
    ur codings are working excelent.

  4. #4
    Join Date
    Dec 2005
    Posts
    266
    Quote Originally Posted by pootle flump
    Why are you not using Round and using Cast ? Why not leave this to the front end to handle ?
    I cannot use 1.2222222222222222222222
    I need 1.22 I must round the result, but the result is a string

  5. #5
    Join Date
    Dec 2005
    Posts
    266
    Quote Originally Posted by pootle flump
    ... and totty.tot in my last bit of help is more efficient (logically anyway - unless SQL Server figures out what you are doing and optimises the query).
    I have tried your totty.tot but it does not work, I get the result in another way

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •