| Author |
Topic |
|
shan1430
Yak Posting Veteran
86 Posts |
Posted - 2008-04-10 : 04:58:43
|
| Hi, I need to update column week14 in table PastWeeks with data from Eng_Goal and then result of some calculation from table AverageEngTime in the row Goal and Used respectively. I used the following and was not successful. Please advice. Thank you.Update Pastweeks setweek14 = (SELECT Eng_Goal,((Mon_Day + Mon_Night + Tue_Day + Tue_Night + Wed_Day + Wed_Night + Thu_Day + Thu_Night + Fri_Day + Fri_Night + Sat_Day + Sat_Night + Sun_Day + Sun_night)* 100/168) FROM AverageEngTime where Shifts = 'Average')where Weeks = ('Goal','Used' ) |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-04-10 : 05:02:39
|
| Subquery should return maximum one column and one row when you are using it for update purpose. Post some sample data and expected output.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
shan1430
Yak Posting Veteran
86 Posts |
Posted - 2008-04-10 : 05:10:34
|
| sample output in Pastweeks, 7 is the Eng_Goal that should be updated in "Goal" and the result of the calculation should be updated in "Used" row.Weeks|Week1|Week2.....|Week14Goal...|.........|..............|7Used..|.........|..............|3.5 |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-04-10 : 05:24:39
|
| Is there any relation or common column between these two tables - PastWeeks and AverageEngTime ?Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts |
Posted - 2008-04-10 : 05:25:50
|
| shan1430As an aside to your question, I recommend you read up a bit on database normalization. This will get you started, and there's plenty of further reading at the bottom...http://en.wikipedia.org/wiki/Database_normalizationThe structures you seem to be working with are going to cause you more headaches than you need.Ryan Randall Solutions are easy. Understanding the problem, now, that's the hard part. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-04-10 : 05:28:17
|
[code]UPDATE pwSET pw.Week14 = FROM PastWeeks AS pwINNER JOIN ( SELECT Eng_Goal, (Mon_Day + Mon_Night + Tue_Day + Tue_Night + Wed_Day + Wed_Night + Thu_Day + Thu_Night + Fri_Day + Fri_Night + Sat_Day + Sat_Night + Sun_Day + Sun_night) * 100.0 / 168.0 FROM AverageEngTime WHERE Shifts = 'Average' ) AS x ON x.Eng_Goal = pw.WeeksWHERE pw.Weeks IN ('Goal', 'Used')[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
|
shan1430
Yak Posting Veteran
86 Posts |
Posted - 2008-04-10 : 21:31:46
|
| I received the following error for youe query..Msg 156, Level 15, State 1, Line 3Incorrect syntax near the keyword 'FROM'.Msg 156, Level 15, State 1, Line 9Incorrect syntax near the keyword 'AS'. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-04-11 : 05:40:18
|
quote: Originally posted by Peso
UPDATE pwSET pw.Week14 = new_valueFROM PastWeeks AS pwINNER JOIN ( SELECT Eng_Goal, (Mon_Day + Mon_Night + Tue_Day + Tue_Night + Wed_Day + Wed_Night + Thu_Day + Thu_Night + Fri_Day + Fri_Night + Sat_Day + Sat_Night + Sun_Day + Sun_night) * 100.0 / 168.0 as new_value FROM AverageEngTime WHERE Shifts = 'Average' ) AS x ON x.Eng_Goal = pw.WeeksWHERE pw.Weeks IN ('Goal', 'Used') E 12°55'05.25"N 56°04'39.16"
MadhivananFailing to plan is Planning to fail |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-04-11 : 07:05:53
|
Thanks Madhi! E 12°55'05.25"N 56°04'39.16" |
 |
|
|
|