February 19, 2010 at 2:46 am
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?
February 19, 2010 at 2:53 am
CREATE TABLE dbo.mytable
( low int, high int, myavg AS (low / high)*100 ) ;
?
I Have Nine Lives You Have One Only
THINK!
February 19, 2010 at 2:58 am
erin.peachey (2/19/2010)
HIi 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
February 19, 2010 at 6:40 am
...and here is the link to that section of Books Online:
http://msdn.microsoft.com/en-us/library/ms191250.aspx
Click and enjoy.
Paul
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
March 7, 2010 at 10:12 am
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