Click here to Skip to main content
15,397,169 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
OriginalGriff 29-Aug-14 8:34am
   
Sorry?
That doesn't make any sense to me:
"i need that my total column value are set in place of '24'. and cal result is base on total column value."
What do you mean?
Perhaps an example would help?

Use the "Improve question" widget to edit your question and provide better information.
Herman<T>.Instance 29-Aug-14 8:50am
   
It made me think a while too!
TCS54321 29-Aug-14 8:40am
   
sir, i want to say that in place of 24 i want that value of total.. like in first time 6 set in place of 24, then 7 set, then 5 and so on.
Thanks7872 29-Aug-14 8:42am
   
use reply button on comment.
TCS54321 29-Aug-14 8:42am
   
ok

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
   
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