Lajith
Lajith

Reputation: 1867

batchwise Sql script to execute in SSIS

I have SQL script which will generate millions of rows and insert to DB table. How can I execute that script in SSIS in batchwise? Is there any easier solution?

Example:

declare @userinput1 int =1
declare @userinput2 int =10000000;


INSERT INTO table2(col1)
SELECT ones.n + 10*tens.n + 100*hundreds.n + 1000*thousands.n + 10000*laks.n+100000*laks10.n +1000000*crore.n
FROM (VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) ones(n),
     (VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) tens(n),
     (VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) hundreds(n),
     (VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) thousands(n),
     (VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) laks(n),
     (VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) laks10(n),
     (VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) crore(n)
WHERE ones.n + 10*tens.n + 100*hundreds.n + 1000*thousands.n + 10000*laks.n +100000* laks10.n +1000000*crore.n  BETWEEN @userinput1 AND @userinput2
ORDER BY 1

Upvotes: 0

Views: 144

Answers (1)

Tab Alleman
Tab Alleman

Reputation: 31775

Use a WHILE loop and only insert a batch at a time, starting from @UserInput1, until you reach @UserInput2.

Upvotes: 1

Related Questions