T-SQL 跑迴圈的寫法

用while可以達到類似程式語法for的功能。

DECLARE @i INT , @j INT , @SQL varchar(1000)
SET @i = 10
SET @j = 12
WHILE (@i <= @j)
BEGIN

set @SQL = ‘

update TableA set TableA.col1 = a.col1
from TableA a with(nolock)
inner join TableB b with(nolock)
on a.ProdId = b.ProdId

print (@SQL);

exec (@SQL);

Set @i = @i + 1

END

by mhchen15 on 24 12 月, 2015 in 未分類

There are no comments.

Name*: Website: E-Mail*:
XHTML: You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>