Hi all,
I am trying to sequence rows in a table. this is for different policy#'s
I am using policy#,effectiveDate as my critiria to start my numbering. The
problem is there are no unique Identifiers in this table I have 6 rows that
are exact dupes. when I run a normal cursor, it updates all 6 with the same
seqNo( I understand why).
I can't get the statement where current of cursorName to work. I get an
error saying:
"Msg 16929, Level 16, State 1, Line 35
The cursor is READ ONLY.
The statement has been terminated."
I need to be able to update ONLY the row in the cursor...
I am including my code below..................Yes TransTime can also be a
dupe.
Any help would be greatly appreciated.
Joe
/******************************/
declare @seqid int, @PolicyNo nvarchar(10), @EffDate datetime,
@TransactionDate datetime, @TranactionTime float,
@KeyHold nvarchar(255),@Key nvarchar(255)
select @seqid=0
Select @keyHold = ' '
Select @key = ' '
declare SEQID cursor for
select policyNo,EffDate,Transactiondate,TranactionTime
from tblpolicyTest
order by policyNo,EffDate,Transactiondate,TranactionTime
open seqid
fetch next from seqid into
@PolicyNo,@EffDate,@TransactionDate,@TranactionTime
while @@fetch_status=0
begin
Select @key = rtrim(isnull(@PolicyNo,' '))+rtrim(isnull(@EffDate,' '))
if @key <> @keyHold
begin
select @seqid =1
update tblpolicyTest
set SeqNo = @seqid
where current of seqid
-- Where PolicyNo = @PolicyNo
-- And EffDate = @EffDate
-- And TransactionDate = @TransactionDate
-- And TranactionTime = @TranactionTime
end
else
begin
select @seqid =@seqid+1
update tblpolicyTest
set SeqNo = @seqid
where current of seqid
-- Where PolicyNo = @PolicyNo
-- And EffDate = @EffDate
-- And TransactionDate = @TransactionDate
-- And TranactionTime = @TranactionTime
end
Select @keyHold = rtrim(isnull(@PolicyNo,' '))+rtrim(isnull(@EffDate,' '))
fetch next from seqid into
@PolicyNo,@EffDate,@TransactionDate,@TranactionTime
end
close seqid
deallocate Seqid
/***************************************/
I am trying to sequence rows in a table. this is for different policy#'s
I am using policy#,effectiveDate as my critiria to start my numbering. The
problem is there are no unique Identifiers in this table I have 6 rows that
are exact dupes. when I run a normal cursor, it updates all 6 with the same
seqNo( I understand why).
I can't get the statement where current of cursorName to work. I get an
error saying:
"Msg 16929, Level 16, State 1, Line 35
The cursor is READ ONLY.
The statement has been terminated."
I need to be able to update ONLY the row in the cursor...
I am including my code below..................Yes TransTime can also be a
dupe.
Any help would be greatly appreciated.
Joe
/******************************/
declare @seqid int, @PolicyNo nvarchar(10), @EffDate datetime,
@TransactionDate datetime, @TranactionTime float,
@KeyHold nvarchar(255),@Key nvarchar(255)
select @seqid=0
Select @keyHold = ' '
Select @key = ' '
declare SEQID cursor for
select policyNo,EffDate,Transactiondate,TranactionTime
from tblpolicyTest
order by policyNo,EffDate,Transactiondate,TranactionTime
open seqid
fetch next from seqid into
@PolicyNo,@EffDate,@TransactionDate,@TranactionTime
while @@fetch_status=0
begin
Select @key = rtrim(isnull(@PolicyNo,' '))+rtrim(isnull(@EffDate,' '))
if @key <> @keyHold
begin
select @seqid =1
update tblpolicyTest
set SeqNo = @seqid
where current of seqid
-- Where PolicyNo = @PolicyNo
-- And EffDate = @EffDate
-- And TransactionDate = @TransactionDate
-- And TranactionTime = @TranactionTime
end
else
begin
select @seqid =@seqid+1
update tblpolicyTest
set SeqNo = @seqid
where current of seqid
-- Where PolicyNo = @PolicyNo
-- And EffDate = @EffDate
-- And TransactionDate = @TransactionDate
-- And TranactionTime = @TranactionTime
end
Select @keyHold = rtrim(isnull(@PolicyNo,' '))+rtrim(isnull(@EffDate,' '))
fetch next from seqid into
@PolicyNo,@EffDate,@TransactionDate,@TranactionTime
end
close seqid
deallocate Seqid
/***************************************/