0

これが私のスクリプトの一部です:

DECLARE @dataId int = 123               

-- Here I run more SQL scripts using @dataId

Select from table A where id = @dataId 

-- So on it goes in other tables and delete and update other tables

私の質問は、100 個の値を入力@dataIdしてスクリプトを順番に繰り返す方法はありますか? @dataId毎回手動で入力するよりも、SQL Server 2008 でこれを行う簡単な方法はありますか?

4

1 に答える 1

0

CURSORSさて、あなたのコメントによると、それが進むべき道だと思います。このようなことをする必要があります:

DECLARE @dataId int

DECLARE DataIds CURSOR LOCAL STATIC READ_ONLY FORWARD_ONLY FOR
SELECT DataId
FROM YourTableWithDataIdsHere

OPEN DataIds
FETCH NEXT FROM DataIds INTO @dataId
WHILE @@FETCH_STATUS = 0
BEGIN

    -- Here I run more SQL scripts using @dataId

    Select from table A where id = @dataId 

    -- So on it goes in other tables and delete and update other tables

    FETCH NEXT FROM DataIds INTO @dataId
END

CLOSE DataIds
DEALLOCATE DataIds
于 2012-11-07T21:21:29.870 に答える