| Author |
Topic |
|
Jayeeta Mitra
Starting Member
11 Posts |
Posted - 2008-03-05 : 06:32:33
|
| I want to add four fields of a table and place the toatal in a new field.Also I wanna have the average of the fields.For e.gI have created a marksheet having four subjects.Now I wanna add the subjects and find the average of the subjects and place them in two different fields in the same table along with the respective names in the table.Pls help.Thanks in advance. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-03-05 : 06:34:54
|
| [code]UPDATE YourTableSET SubjectTotal=Sub1+Sub2+Sub3+Sub4, SubAvg=(Sub1+Sub2+Sub3+Sub4)/4[/code] |
 |
|
|
Jayeeta Mitra
Starting Member
11 Posts |
Posted - 2008-03-05 : 06:36:15
|
| I want to do this through functions. |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-03-05 : 06:37:45
|
| [code]declare @t table( id int identity(1,1), s1 int, s2 int, s3 int)insert @tselect 26, 78, 57 union allselect 23,95,75 union allselect 17,69,63select id, (s1+s2+s3) as tot, (s1+s2+s3)/3 as avfrom @t[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-03-05 : 06:38:21
|
| You can't update a physical table through UDF.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-03-05 : 06:38:22
|
| why? also, i guess you actually mean a procedure rather than a function?Em |
 |
|
|
Jayeeta Mitra
Starting Member
11 Posts |
Posted - 2008-03-05 : 06:40:59
|
| I wanna make this with both procedure and function |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-03-05 : 06:45:14
|
Why? Because your teacher asked you to do it as a homework? Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-03-05 : 06:48:21
|
| both? what do want to acheive with a function though? you just need a procedure to perform the update statement that visakh gave youEm |
 |
|
|
|