SQL virtual column

  • HI

    i am pretty new to SQL and what you can and can't do so please help me if you can.

    I'm trying to take a value from a colomn, devide it by another value from another colomn and then express that result in % in a virtual colomn. is this possible?

  • CREATE TABLE dbo.mytable

    ( low int, high int, myavg AS (low / high)*100 ) ;

    ?

    I Have Nine Lives You Have One Only
    THINK!

  • erin.peachey (2/19/2010)


    HI

    i am pretty new to SQL and what you can and can't do so please help me if you can.

    I'm trying to take a value from a colomn, devide it by another value from another colomn and then express that result in % in a virtual colomn. is this possible?

    If I understand you correctly then yes it is possible. Look in BOL (Books On-Line) for the subject of 'Computed Columns'.

    BrainDonor

  • ...and here is the link to that section of Books Online:

    http://msdn.microsoft.com/en-us/library/ms191250.aspx

    Click and enjoy.

    Paul

  • select col1,col2, case when col2=0 then '0' else (col1/col2)*100 end [percentage]

    from tablename

Viewing 5 posts - 1 through 4 (of 4 total)

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