Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
sir, i have a query like:-

C#
select	(Studentid+semid) as total , 30+((50-30)* (cast(24 as float)/cast(50 as float))) as cal 
from student

the result of query is :-

total -- cal
6 -- 39.6
7 -- 39.6
5 -- 39.6
8 -- 39.6


i need that my total column value are set in place of '24'. and cal result is base on total column value. how can i do it.
Posted
Updated 29-Aug-14 2:30am
v2
Comments
Vinay Mistry 29-Aug-14 8:34am    
Replace your value by column name
TCS54321 29-Aug-14 8:41am    
sir, its not working, it said invalid column
Herman<T>.Instance 29-Aug-14 8:49am    
true, you should use (StundetID+SemId) again in stead of 24
TCS54321 29-Aug-14 8:55am    
yes sir.. its working.. thanku
Herman<T>.Instance 29-Aug-14 8:58am    
good luck

1 solution

Hi,
Hope the below code solve your problem.

SQL
WITH Sample_CTE (total)
AS
(
    SELECT (Studentid+semid) as total from student
   
)
SELECT 30+((50-30)* (cast(total as float)/cast(50 as float)))  AS cal
FROM Sample_CTE;


(if yes pls mark as solved)

Thanks
 
Share this answer
 
v3
Comments
TCS54321 29-Aug-14 8:52am    
sir, 100 is a hardcode. every time it take 100 in place of total??
Faisal(mfrony) 29-Aug-14 9:10am    
Is that ok Now ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900