PDA

View Full Version : Cursor into Transaction or Query?


benq
05-21-06, 10:59 AM
hi

i have this cursor and i would like to change it into a transactio or a Query, can some one help with please.

declare csr1 cursor
for select booking_no from holiday
for read only

begin tran
declare @holiday varchar(50)

open csr1

FETCH NEXT FROM csr1
INTO @holiday

-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN

SELECT @holiday as Booking,
(select SUM(distance_in_miles)
from holiday, allocated, route_on_stage, stage
where holiday.booking_no = allocated.booking_no
and allocated.route_no = route_on_stage.route_no
and route_on_stage.stage_no = stage.stage_no
and holiday.booking_no = @holiday) as Distance,
(select SUM(cost_per_nite_per_person) * (
SELECT number_of_clients FROM allocated, holiday, holiday_party
WHERE holiday.booking_no = allocated.booking_no
AND allocated.party_no = holiday_party.party_no
AND holiday.booking_no = @holiday
) as total_cost
from holiday, allocated, route_on_stage, stage, accomdation, rooms
where holiday.booking_no = allocated.booking_no
and allocated.route_no = route_on_stage.route_no
and route_on_stage.stage_no = stage.stage_no
and stage.accomdation_at_end = accomdation.accomdation_name
and accomdation.accomdation_no = rooms.accomdation_no
and holiday.booking_no = @holiday) as Cost

-- This is executed as long as the previous fetch succeeds.
FETCH NEXT FROM csr1
INTO @holiday
END

CLOSE csr1
DEALLOCATE csr1

commit tran


thanks for your time