Hi,
I need to update the top 20 percent records within a 50 mile radius inside the file with an "A" in the keycode field. The catch? It needs to start at the top 20 percent when the dealer # changes.
I haven't really started much because I'm being told the only way is a cursor and I really don't want to do that if possible since the file is huge...
This is what someone sent me to start with....
Any assistance would be greatly appreciated!!!
Elena
DECLARE @dlrnmbr varchar(10)
--declare the cursor which is basically the name of the bucket
DECLARE addDealerSegment CURSOR
FOR
select distinct dlrnmbr
from an_clientdata_temp
where cast(distance as numeric(10,0)) <= 50
order by dlrnmbr
--declare the counter (not needed for cursor but I like to watch it when it runs)
DECLARE @count int
SELECT @count = 1
--this is actually what loads the information to be called
OPEN addDealerSegment
FETCH NEXT FROM addDealerSegment INTO @dlrnmbr
-- this is the beginning of the loop
WHILE (@@fetch_status <> -1)
BEGIN
IF (@@fetch_status <> -2)
BEGIN
PRINT 'inserting records for dealer ' + @dlrnmbr
insert into tbldealersegment
select cast(@dlrnmbr as varchar(10))
END
FETCH NEXT FROM addDealerSegment INTO @dlrnmbr
SELECT @count = @count + 1
END
CLOSE addDealerSegment
DEALLOCATE addDealerSegment
GO
I need to update the top 20 percent records within a 50 mile radius inside the file with an "A" in the keycode field. The catch? It needs to start at the top 20 percent when the dealer # changes.
I haven't really started much because I'm being told the only way is a cursor and I really don't want to do that if possible since the file is huge...
This is what someone sent me to start with....
Any assistance would be greatly appreciated!!!
Elena
DECLARE @dlrnmbr varchar(10)
--declare the cursor which is basically the name of the bucket
DECLARE addDealerSegment CURSOR
FOR
select distinct dlrnmbr
from an_clientdata_temp
where cast(distance as numeric(10,0)) <= 50
order by dlrnmbr
--declare the counter (not needed for cursor but I like to watch it when it runs)
DECLARE @count int
SELECT @count = 1
--this is actually what loads the information to be called
OPEN addDealerSegment
FETCH NEXT FROM addDealerSegment INTO @dlrnmbr
-- this is the beginning of the loop
WHILE (@@fetch_status <> -1)
BEGIN
IF (@@fetch_status <> -2)
BEGIN
PRINT 'inserting records for dealer ' + @dlrnmbr
insert into tbldealersegment
select cast(@dlrnmbr as varchar(10))
END
FETCH NEXT FROM addDealerSegment INTO @dlrnmbr
SELECT @count = @count + 1
END
CLOSE addDealerSegment
DEALLOCATE addDealerSegment
GO