Hello! I have read over this post but cannot get the code to work
https://learn.microsoft.com/en-us/answers/questions/565584/best-approach-to-load-data-from-table-with-billion.html
I have a table with almost 7 billion records in it which I am trying to query. The approach I am attempting involves querying 'smaller' (I realize it's still a lot of data) subsets of 100m records at a time, get the results of the 100m query and put those results in a temp table, move on to the next 100m, query those records, put the results in the result temp table and so on.
Here is my code:
Declare @minID as bigint, @maxID as bigint, @batchsize as bigint = 100000
WHILE @minID IS NOT NULL
BEGIN
SELECT @maxID = MAX(AppDetailID)
FROM (SELECT TOP (@batchsize) AppDetailID FROM dbo.ApplicationDetail
WHERE AppDetailID >= @minID and ClaimID <> 0 and ReceiptID <> 0 and AppType = ('CA'))
INSERT INTO #result (AppDetailID, ReceiptID, ClaimID, AdjustAmt, SessionNbr)
SELECT AppDetailID, ReceiptID, ClaimID, AdjustAmt, SessionNbr
FROM dbo.ApplicationDetail
WHERE AppDetailID between @minID and @maxID)
END
I am getting an error at the section SELECT @maxID = MAX(AppDetailID)
I really appreciate your help understanding what I am doing wrong