Click here to Skip to main content
15,905,781 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
HI,

I am going to one calculation. Below are my code. I want to select some data in temp table and i do that calculation for all the values intblCAL_PLAN. and save that to same table. how can i do this?
Here DAYSINMONTH has 12 values(30,31....) I do the calculation for this 12 values and save withinit.
Anyone help me to do this?


SQL
UPDATE dbo.tblCAL_PLAN SET AVAILBLEBED=
  (
  (SELECT AVAILBLEBEDDAYS FROM #TEMP_FA_2003)/
  ((SELECT DAYSINMONTH FROM #TEMP_FA_2003) *
  (SELECT DAYSINMONTH FROM dbo.tblCAL_PLAN WHERE FACILITY='FA_2003')
  ))
Posted
Comments
Tomas Takac 14-Mar-14 16:57pm    
Could you edit your question and post structure of tblCAL_PLAN, #TEMP_FA_2003 and the query you use to populate #TEMP_FA_2003?

1 solution

To update table with SELECT statement, try this:
SQL
UPDATE t1 SET t1.Field1 = t2.AVAILBLEBEDDAYS/t2.DAYSINMONTH *t1.DAYSINMONTH 
FROM tblCAL_PLAN AS t1 INNER JOIN #TEMP_FA_2003 AS t2 ON t1.Key = t2.ForeignKey
WHERE t1.FACILITY='FA_2003'
 
Share this answer
 

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