SELECT t.* FROM (
SELECT ROW_NUMBER() OVER(ORDER BY b.booking_no) AS rownum,
b.flight_booking_seq as flightBookingSeq,
b.booking_no as bookingNo,
isnull(b.first_name,'')+' '+isnull(b.last_name,'') as bookName,
b.mobile_phone as mobilePhone,
b.work_phone as workPhone,
(SELECT COUNT(ck.check_in_seq)
FROM ka_check_in ck
WHERE ck.passenger_type <> 'I'
AND ck.flight_itinerary_seq = i.flight_itinerary_seq) as passengerNo,
ei.item_desc as bookingStatus,
i.flight_itinerary_seq as flightItinerarySeq,
case b.round_trip
when 'Y' then 'true'
else 'false'
end as roundTrip,
b.booking_note as bookingNote,
b.email as email,
dbo.get_check_in_status(i.flight_itinerary_seq) as checkInStatus,
b.booking_status,
isnull(dbo.get_count_bag_booking(i.flight_itinerary_seq),'') as bagNoBook,
dbo.get_booking_by(b.flight_booking_seq) as bookingBy
from ka_flight_sche s , ka_flight_itinerary i , ka_flight_booking b , sc_entry_item ei
where s.flight_sche_seq = i.flight_sche_seq
and i.flight_booking_seq = b.flight_booking_seq
and s.flight_sche_seq = '5179'
and ei.param_code = 'KA0001'
and ei.entry_code = '1'
and ei.item_code = b.booking_status
and b.booking_status = 'N'
) as t