Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 ;with cte - -Help

Author  Topic 

best_boy26
Starting Member

42 Posts

Posted - 2011-03-18 : 15:13:37
select * from dbo.v_Devide

I have a SQL table with below DDL.


USE [abc]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[v_Devide](
[i_S.NO] [nchar](10) NULL,
[data_14] [money] NULL,
[data_15] [money] NULL
) ON [PRIMARY]

GO


When i run a SQL Query

select * from dbo.v_Devide 


I have below data in the table


i_S.NO data_14 data_15
1 0.721426829 0.828569686
2 0.680610191 0.769386137
3 0.631995177 0.857287127
4 0.586852665 0.838909911
5 0.544934617 0.886130631
6 0.506010716 1.087122172
7 0.5662961 1.009470588
8 0.529419115 0.937365546
9 0.548745449 0.870410864


Now I want to perform a caluculation againest of data_14 and Data_15 and end as a new column

and in the end as new column I should caluculate the = 100-(100/(1+data_14/Data_15))

this should be done on each row ending... on complete table...

so expected results would be...


i_S.NO data_14 data_15 New Column
1 0.721426829 0.828569686 46.54377103
2 0.680610191 0.769386137 46.93875273
3 0.631995177 0.857287127 42.43622417
4 0.586852665 0.838909911 41.16061641
5 0.544934617 0.886130631 38.07894976
6 0.506010716 1.087122172 31.76199046
7 0.5662961 1.009470588 35.93781392
8 0.529419115 0.937365546 36.09385404
9 0.548745449 0.870410864 38.66701955


Thanks in Advance..
JJ

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-03-18 : 15:25:54
SELECT *
,[newColumn] =
100-(100/(1+data_14/Data_15))

FROM dbo.v_Devide

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

best_boy26
Starting Member

42 Posts

Posted - 2011-03-18 : 15:35:31
This one really super worked for me Jimf
Go to Top of Page
   

- Advertisement -