Professional Web Applications Themes

SQL View with Decimal Output - Microsoft SQL / MS SQL Server

Is there anyway to specify that a calculated field in a view be displayed as a decimal? Thank you, Heidi...

  1. #1

    Default SQL View with Decimal Output

    Is there anyway to specify that a calculated field in a
    view be displayed as a decimal?

    Thank you,
    Heidi
    Heidi Guest

  2. #2

    Default Re: SQL View with Decimal Output

    Heidi

    You need to explicitly convert the calculated field as decimal by using
    convert.

    for eg: select Convert(decimal(10,3),2*3) as DecimalOutput


    HTH

    Praveen Maddali,
    MCSD, MCDBA


    "Heidi Stoneman" <com> wrote in message
    news:05d001c34d1f$9f7bc700$gbl... 


    praveen Guest

  3. #3

    Default Re: SQL View with Decimal Output

    It would help if you posted the error. Help alot if you post create table
    code & sample data.

    Guessing it is divide by zero problem.

    Solution add nullif value is zero.

    SELECT Member, FiscalYear, SUM(CC) + SUM(SDS) + SUM
    (Datanet) + SUM(XCAT) + SUM(RTWZ) AS Electric_Total,
    CONVERT(decimal(10, 3), (SUM(CC) + SUM(SDS) + SUM(Datanet)
    + SUM(XCAT) + SUM(RTWZ)) /
    (
    NULLIF(
    SUM(CC) + SUM(SDS) + SUM
    (Datanet) + SUM(XCAT) + SUM(RTWZ) + SUM(ODEN) + SUM
    (Telxon) + SUM(ECom)
    , 0)
    )
    ) AS Expr1 FROM dbo.MBR_OrderSummary
    GROUP BY Member, FiscalYear ORDER BY Member, FiscalYear


    SELECT Member, FiscalYear, SUM(CC) + SUM(SDS) + SUM
    (Datanet) + SUM(XCAT) + SUM(RTWZ) AS Electric_Total,
    CONVERT(decimal(10, 3), (SUM(CC) + SUM(SDS) + SUM(Datanet)
    + SUM(XCAT) + SUM(RTWZ)) / (SUM(CC) + SUM(SDS) + SUM
    (Datanet) + SUM(XCAT) + SUM(RTWZ) + SUM(ODEN) + SUM
    (Telxon) + SUM(ECom))) AS Expr1 FROM dbo.MBR_OrderSummary
    GROUP BY Member, FiscalYear ORDER BY Member, FiscalYear



    "Heidi Stoneman" <com> wrote in message
    news:0d6c01c34d28$81d0ef10$gbl... 
    > decimal by using 
    > >
    > >
    > >.
    > >[/ref][/ref]



    Tim Guest

Similar Threads

  1. Question i need to display 3 decimal values in my output
    By Unregistered in forum Brainstorming Area
    Replies: 0
    Last Post: September 12th, 07:29 AM
  2. Replies: 1
    Last Post: October 10th, 06:11 PM
  3. Standard View vs. Layout View
    By Joe {RoastHorse} in forum Macromedia Dreamweaver
    Replies: 1
    Last Post: July 23rd, 04:03 PM
  4. Code view & Layout view
    By SamEl webforumsuser@macromedia.com in forum Macromedia Dreamweaver
    Replies: 6
    Last Post: July 22nd, 07:35 PM
  5. Wierd error when going to Design View from HTML view
    By VB Programmer in forum ASP.NET General
    Replies: 1
    Last Post: July 10th, 03:20 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139