LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Cursor into Transaction or Query? (https://www.linuxquestions.org/questions/programming-9/cursor-into-transaction-or-query-447003/)

ati 05-21-2006 09:59 AM

Cursor into Transaction or Query?
 
hi

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

Code:

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

chrism01 05-23-2006 02:45 AM

Your qn is unclear; that is an SQL query (or at least the SELECT ... is).
You've got 'commit tran' at the end already, although it's unnecessary for SELECTs as no change is made to the DB.
Can you expand a bit?


All times are GMT -5. The time now is 08:28 PM.