我需要編寫一個存儲過程。 我有一個表的一些數據現在我需要根據一些條件相關數據插入到另一個表基於另一個表在表中插入值
實施例:
Table 1
Name Class Math Physics English
Alok V 60 50 45
Bobby V 78 87 86
Chandini VI 56 76 56
Dolly VII 87 56 66
基於此條件
Insert Values into Table2
If class =V
(Table2.Physics=Select sum(Table1.Physics) from Table1 where Class like ‘V’
Table2.Maths=0 and table2.English=0)
If class =VI
(Table2.Maths=Select sum(Table1.Maths) from Table1 where Class like ‘VI’
Table2.Physics=0 and table2.English=0)
If class =VI
(Table2.English =Select sum(Table1.English) from Table1 where Class like ‘VII’
Table2.Physics=0 and table2.Maths =0)
]
Table 2
Class Math Physics English
V 0 137 0
VI 56 0 0
VII 0 0 66
請幫我解決
看看這是否有幫助http://blog.sqlauthority.com/2007/08/15/sql-server-insert-data-from-one-table- to-another-table-insert-into-select-select-into-table/ – ashishjmeshram 2011-03-28 13:32:05