-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy path02-step-schedule-view.sql
42 lines (38 loc) · 1.26 KB
/
02-step-schedule-view.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
===========================================
Step Schedule View Creation
===========================================
*/
-- Step Schedule View Input Table
@stepsTableExample = select
'AssetID' as [AssetID],
'2021-09-15T00:00:00+00:00' as [Date],
1 as [Quantity];
@createStepScheduleJsonView = use Sys.Admin.SetupView with @stepsTableExample
--provider=Schedules.Step_Schedule
--description="Outputs a table with two columns containing the asset ID and the formatted step schedule json"
--parameters
LevelType,Text,Absolute,true
StepScheduleType,Text,Coupon,true
StepsTable,Table,@stepsTableExample,true
AssetFilter, Text, AssetFilter, true
----
@@levelType = select #PARAMETERVALUE(LevelType);
@@stepScheduleType = select #PARAMETERVALUE(StepScheduleType);
@@assetFilter = select #PARAMETERVALUE(AssetFilter);
@stepsTable = select * from #PARAMETERVALUE(StepsTable) where AssetID = @@assetFilter;
select
st.[AssetID],
json_object(
'steps', json_group_array(
json_object(
'date', st.[Date],
'quantity', cast(st.[Quantity] as double)
)
),
'levelType', @@levelType,
'stepScheduleType', @@stepScheduleType,
'scheduleType', 'Step'
) as JsonString
from @stepsTable st;
enduse;