UFN_SALESORDER_RESERVATION_RESOURCES_FLAT
Return
Return Type |
---|
table |
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@SALESORDERID | uniqueidentifier | IN |
Definition
Copy
create function dbo.UFN_SALESORDER_RESERVATION_RESOURCES_FLAT (@SALESORDERID uniqueidentifier)
returns table
as
return
(
select max(case RowNum when 1 then DESCRIPTION else null end) as RSCDESC1,
max(case RowNum when 1 then STARTDATE else null end) as RSCSTDT1,
max(case RowNum when 1 then ENDDATE else null end) as RSCENDDT1,
sum(case RowNum when 1 then QUANTITY else null end) as RSCQTY1,
sum(case RowNum when 1 then PRICE else null end) as RSCPRICE1,
sum(case RowNum when 1 then TOTAL else null end) as RSCTOTAL1,
max(case RowNum when 2 then DESCRIPTION else null end) as RSCDESC2,
max(case RowNum when 2 then STARTDATE else null end) as RSCSTDT2,
max(case RowNum when 2 then ENDDATE else null end) as RSCENDDT2,
sum(case RowNum when 2 then QUANTITY else null end) as RSCQTY2,
sum(case RowNum when 2 then PRICE else null end) as RSCPRICE2,
sum(case RowNum when 2 then TOTAL else null end) as RSCTOTAL2,
max(case RowNum when 3 then DESCRIPTION else null end) as RSCDESC3,
max(case RowNum when 3 then STARTDATE else null end) as RSCSTDT3,
max(case RowNum when 3 then ENDDATE else null end) as RSCENDDT3,
sum(case RowNum when 3 then QUANTITY else null end) as RSCQTY3,
sum(case RowNum when 3 then PRICE else null end) as RSCPRICE3,
sum(case RowNum when 3 then TOTAL else null end) as RSCTOTAL3,
max(case RowNum when 4 then DESCRIPTION else null end) as RSCDESC4,
max(case RowNum when 4 then STARTDATE else null end) as RSCSTDT4,
max(case RowNum when 4 then ENDDATE else null end) as RSCENDDT4,
sum(case RowNum when 4 then QUANTITY else null end) as RSCQTY4,
sum(case RowNum when 4 then PRICE else null end) as RSCPRICE4,
sum(case RowNum when 4 then TOTAL else null end) as RSCTOTAL4,
max(case when RowNum > 4 then 'Other resources' else null end) as RSCDESCREST,
sum(case when RowNum > 4 then TOTAL else null end) as RSCTOTALREST
from
(select DESCRIPTION, STARTDATE, ENDDATE, QUANTITY, PRICE, TOTAL, row_number() over (order by TOTAL desc) as RowNum
from dbo.UFN_SALESORDER_RESERVATION_RESOURCES(@SALESORDERID)) V1
)