UFN_SALESORDER_ITINERARY_FLAT

Return

Return Type
table

Parameters

Parameter Parameter Type Mode Description
@SALESORDERID uniqueidentifier IN

Definition

Copy


        create function dbo.UFN_SALESORDER_ITINERARY_FLAT (@SALESORDERID uniqueidentifier)
        returns table
        as
        return (
            select max(case RowNum when 1 then ITINERARYNAME else null end) as ITINNAME1,
                max(case RowNum when 1 then LEADERNAME else null end) as ITINLDR1,
                max(case RowNum when 1 then GROUPTYPE else null end) as ITINGT1,
                max(case RowNum when 1 then STARTTIME else null end) as ITINST1,
                max(case RowNum when 1 then ENDTIME else null end) as ITINET1,
                max(case RowNum when 2 then ITINERARYNAME else null end) as ITINNAME2,
                max(case RowNum when 2 then LEADERNAME else null end) as ITINLDR2,
                max(case RowNum when 2 then GROUPTYPE else null end) as ITINGT2,
                max(case RowNum when 2 then STARTTIME else null end) as ITINST2,
                max(case RowNum when 2 then ENDTIME else null end) as ITINET2,
                max(case RowNum when 3 then ITINERARYNAME else null end) as ITINNAME3,
                max(case RowNum when 3 then LEADERNAME else null end) as ITINLDR3,
                max(case RowNum when 3 then GROUPTYPE else null end) as ITINGT3,
                max(case RowNum when 3 then STARTTIME else null end) as ITINST3,
                max(case RowNum when 3 then ENDTIME else null end) as ITINET3,
                max(case RowNum when 4 then ITINERARYNAME else null end) as ITINNAME4,
                max(case RowNum when 4 then LEADERNAME else null end) as ITINLDR4,
                max(case RowNum when 4 then GROUPTYPE else null end) as ITINGT4,
                max(case RowNum when 4 then STARTTIME else null end) as ITINST4,
                max(case RowNum when 4 then ENDTIME else null end) as ITINET4,
                max(case when RowNum > 4 then 'More itineraries...' else null end ) as ITINNAMEREST
            from
                (select ITINERARYNAME, LEADERNAME, GROUPTYPE, NUMBEROFVISITORS, substring(convert(varchar,convert(datetime,stuff(STARTDATETIME,3,0,':')),100),12,8) as STARTTIME, 
                substring(convert(varchar,convert(datetime,stuff(ENDDATETIME,3,0,':')),100),12,8) as ENDTIME, row_number() over (order by STARTDATETIME) as RowNum
                from dbo.UFN_SALESORDER_ITINERARY (@SALESORDERID)) V1
            )