Field Calculation SQL

Discussion in 'ASP General' started by Simon Gare, Jun 12, 2006.

  1. Simon Gare

    Simon Gare Guest

    Hi,

    would like to calculate field based on the entry in another i.e.; field3 =
    field2 X field1



    field1 field2 field3
    10 2.5 25.00( =sum(field1*field2))

    How do I go about this in the SQL DB itself, can it be done within field3?

    Regards
    Simon
     
    Simon Gare, Jun 12, 2006
    #1
    1. Advertising

  2. Simon Gare wrote:
    > Hi,
    >
    > would like to calculate field based on the entry in another i.e.;
    > field3 = field2 X field1
    >
    >
    >
    > field1 field2 field3
    > 10 2.5 25.00( =sum(field1*field2))


    sum? you want an aggregate? if so, you can't show the details ...
    Or are you thinking that you have to use sum() to do any calcualtion? if so,
    that is not the case

    >
    > How do I go about this in the SQL DB itself, can it be done within
    > field3?
    >

    It depends on the version of the database you are using (I assume it's SQL
    Server ... never ask a database-related question without full specifying the
    type and version of the rdbms you are using - it's almost always relevant)

    In SQL7, your only option would be to create a view. Assuming you don't want
    an aggregate:

    CREATE VIEW MyView As
    Select field1,field2,field1*field2 As Result
    From table

    In SQL 2000+, you have other options which I suggest you investigate either
    by reading about them in Books Online or by posting to one of the sqlserver
    newsgroups on this news server.


    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows [MVP], Jun 12, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. J Sahoo
    Replies:
    3
    Views:
    5,291
    naikpalak
    Apr 30, 2009
  2. Emmanuel
    Replies:
    1
    Views:
    672
    Karl Seguin
    Nov 22, 2005
  3. ecoolone
    Replies:
    0
    Views:
    765
    ecoolone
    Jan 3, 2008
  4. Sound
    Replies:
    2
    Views:
    453
    Randy Webb
    Sep 28, 2006
  5. jr
    Replies:
    3
    Views:
    426
Loading...

Share This Page