I have a procedure that contains the following code that works perfectly in ISQL.
Essentially, I SET a random number to each record, then SET another value (panel_code) based on that random number. It works great... with one pass through the table.
UPDATE cheetah.mailing_pool mp
SET
random_nbr = dba.f_rand(record_id) ,
panel_code =
( CASE
WHEN random_nbr >= @panel_a_lower_threshold and random_nbr < @panel_b_lower_threshold then 'A'
WHEN random_nbr >= @panel_b_lower_threshold and random_nbr < @panel_c_lower_threshold then 'B'
WHEN random_nbr >= @panel_c_lower_threshold and random_nbr < @panel_d_lower_threshold then 'C'
WHEN random_nbr >= @panel_d_lower_threshold and random_nbr <= 1 then 'D'
ELSE '!!!' -- error, this shouldn't happen
END )
WHERE mp.mailing_id = @mailing_id;
However, the problem is that when I run it in my application, it fails. The table is updated with a reasonable random number, but the CASE expression drop through to the ELSE every time.
So I tried this...
UPDATE cheetah.mailing_pool mp
SET
random_nbr = dba.f_rand(record_id)
WHERE mp.mailing_id = @mailing_id;
UPDATE cheetah.mailing_pool mp
SET
panel_code =
( CASE
WHEN random_nbr >= @panel_a_lower_threshold and random_nbr < @panel_b_lower_threshold then 'A'
WHEN random_nbr >= @panel_b_lower_threshold and random_nbr < @panel_c_lower_threshold then 'B'
WHEN random_nbr >= @panel_c_lower_threshold and random_nbr < @panel_d_lower_threshold then 'C'
WHEN random_nbr >= @panel_d_lower_threshold and random_nbr <= 1 then 'D'
ELSE '!!!' -- error, this shouldn't happen
END )
WHERE mp.mailing_id = @mailing_id;
And guess what? It works perfectly every time. It never drops though to the ELSE. So what's different?
I've tested the input parameters -- I know all the variables have the same value in the code leading up to the UPDATE... so that left me looking for Connection differences.
The only thing different I can find is the Isolation level -- ISQL comes in at Isolation level 0, and the application (where the one-pass code doesn't work) uses Isolation level 1.
So.. is this a reasonable outcome of using Isolation level 1, or do I have a differnt problem.
Mods... please edit the question. I had no idea how to phrase the question!
Thanks!
I'm using 9.0.2.3850
asked
09 Apr '10, 20:50
Ron Hiner
880●20●24●27
accept rate:
9%