2012-03-14 51 views
1

如何在Storedprocedure中引入行/列的嵌套循環 - 存儲過程非常新穎:(..我有兩個表,有相同的列,我試圖迭代表,並使用它們的值嵌套循環的列和行..在存儲過程

For Each row in Table1 

    For Each row in Table2 

     For Each Column 
     'Here we are in a column Row intersection 
     my value = value of table1 + value of table 2. 

     End loop 'Each Column 

    End loop 'Each row in Table2' 

End loop 'Each row in Table1' 

任何幫助..在此先感謝..

+0

請提供您的表結構和e xample數據/期望的結果,以便我們可以看到你正在嘗試做什麼。 SQL是基於/聲明而不是過程設置的。 – 2012-03-14 13:51:42

+0

同意。這聽起來像你只需要一個簡單的查詢 – Randy 2012-03-14 13:55:10

回答

1

你可以考慮一個簡單的選擇要添加這樣的價值觀:

select t1.value + t2.value as result 
from table1 t1, table2 t2 
where t1.pk = t2.fk