i having major problem, have 2 tables, tablea , tableb
tablea inserting updating
tableb table datetokens, timetokens, tokenorder , taken
i have declared table called @taken copies tableb , puts values in it.
what trying following:
declare @taken table
insert record tablea
get id record inserted tablea via scope_identity()
insert data tableb @taken taken tableb 0 (some records in tableb taken marked 1, want records not taken) in step, redo tokenorder via row_number() on (order tokenorder) tokenorder.
select @taken table new tokenorder equal id new inserted row in tablea
update tablea timetoken , datetoken id equal id new inserted row in tablea
update tableb timetoken , datetoken taken tokenorder equal id new inserted row in tablea
my problem code in stored procedure , put call stored procedure in loop, looping through 200 times , when run it, exact number of rows expecting, results not right.
my table b data looks this
datetoken timetoken tokenorder taken monday 1:00pm 1 0 monday 1:10pm 2 0 monday 1:20pm 3 0
and on way till midnight increasing 10 minutes. (there 3 hour break somewhere in there)
the results when run stored procedure are
datetoken timetoken monday 1:10pm monday 1:30pm monday 1:50pm monday 2:10pm monday 2:30pm
so appears skipping every other timetoken , have no idea why
here code:
@datetoken nvarchar(max) output, @timetoken nvarchar(max) output, declare @tablea_pk bigint declare @taken table( id int not null, datetoken nvarchar(max), timetoken nvarchar(max), tokenorder int, taken bit); insert tablea (datetoken, timetoken) values (‘’, ‘’) set @tablea_pk=scope_identity() insert @taken select id, datetoken, timetoken, row_number() on (order tokenorder) tokenorder, taken tableb taken = 0 select @datetoken = datetoken, @timetoken = timetoken @taken tokenorder = @tablea_pk update tablea set datetoken = @datetoken, timetoken = @timetoken id = @tablea_pk update tableb set taken = 1 tokenorder = @tablea_pk
any appreciated. please help, i've been struggling daysssss
one other thing, when goto @ data in tableb after run code, rows marked taken, expected.
after inserting "tablea" identity value of (@tablea_pk=scope_identity()) increases one.
but calculating tokenorder value "row_number() on (order tokenorder)" , "taken=0" rows. every time starts "1".
that's why code skips rows every run.
for example; in first turn, getting correct result. in second turn, take "token = 2" rows , skip "token = 1".
Comments
Post a Comment