点击此处---> 群内免费提供SAP练习系统(在群公告中)
加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)
嗨
我正在SAP HANA 2.0 Web IDE rev(35)中的日期维计算视图上工作,我创建了一个包含表中所有日期的视图。 现在,我需要创建一些动态日期,包括年初至今,本周和MTD。 我的想法是创建一个表函数,该表函数为我提供一个日期行(当前日期),并使用来自不同列的值来过滤主表格,因此我只能看到想要的日期。
例如
表函数包含以下列
YEAR_ID年
12.03.2019 2019
输入变量
VAR_DAY = 12.03.2019
VAR_Year = 2019
计算尺寸(YTD)
选择*
来自DIM_DATES
其中VAR_DAY 当我尝试使用user_input或变量时,系统提示Im在Web IDE中输入值。 如何强制基于input_variable或参数的过滤器? 最好的问候 Petter Huseby
经过一些测试,我找到了一个好的解决方案:
我已将时间/日期维度导入表格中。 在我看来,HANA时间/日期维度的构建并不理想。 它只是代表月,周和天的数字。 我喜欢有天的名字等等。
我创建了一个Table函数,该函数返回我想要的日期。 并且我创建了多个使用已创建的表函数的计算视图。
以下是获取DATE_YTD的示例
功能" test_db.db :: DATE_YTD"()
RETURNS TABLE(" DAY_ID" NVARCHAR(10)," YEAR_ID" NVARCHAR(4))
语言SQLSCRIPT
SQL安全调用者
重新开始
从" test_db.db :: dates.Entity_LOAD_DATE"中选择" DAY_ID"," YEAR_ID"。DAY_ID <= current_date AND YEAR_ID = TO_NVARCHAR(CURRENT_DATE,'YYYY');
END;
请问您能更详细地描述问题所在吗? 当你有一个计算。 带有参数或表功能的视图,当然您需要提供参数。 因此,"我如何强制基于input_variable或参数的过滤器"是什么意思? 我认为应该清楚参数,过滤器表达式,参数映射等的一般概念吗?
仍然不是100%清楚地告诉我您想详细了解什么。 但是听起来您正在搜索 APPLY_FILTER 函数,该函数使您可以评估数据源上的动态where条件。
嗨,弗洛里安,感谢您的关注。 我将尝试解释我的目标,也许您对如何解决它有一些建议:
我想创建一些代表时间(日期)的维度。 我将创建一个基本维度,该维度在我的时间维度表中包含所有日期。 我将创建层次结构并准备正确的标签,依此类推...完成后,我将复制维度模型并应用过滤器,以便创建动态日期范围,例如Year_to_date。 为此,我需要对时间维度应用过滤条件。 该过滤器将如下所示:day> curret date and year = current year。 我喜欢创建一些参数或user_input,以动态值应用过滤器。 我喜欢应用该Filet,因此它将应用于sql的where语句。 我希望这可以使我的目标更加明确:-)
Br
Petter
这是包含我所有列的完整的Table函数:
FUNCTION" test_db.db :: DATE_YTD"()返回表(" DAY_ID" DATE," UNIX_TIME" NVARCHAR(10)," DAY_CAPTION" NVARCHAR(10)," DAY_OF_CAL_YEAR" NVARCHAR(3)," DAY_OF_CAL_WEEK" NVARCHAR (1)," DAY_OF_WEEK" NVARCHAR(1)," DAY_NAME_ENG" NVARCHAR(9)," DAY_NAME_SHORT_ENG" NVARCHAR(3)," DAY_NAME_NOR" NVARCHAR(7)," DAY_NAME_SHORT_NO" NVARCHAR(3)," DAY_FIRST_DAY_WEEK" DATE DAY_LAST_DAY_WEEK" DATE," DAY_JULIAN_DATE" NVARCHAR(7)," WORKDAY_NOR" NVARCHAR(1)," WORKDAY_ENG" NVARCHAR(1)," WORKDAY_FREE_1" NVARCHAR(1)," WORKDAY_FREE_2" NVARCHAR(1)," DAY_TYPE_NOR" )," DAY_COMPARABLE_LASTYEAR"日期," WEEK_ID" NVARCHAR(6)," WEEK_CAPTION" NVARCHAR(8)," WEEK_NUM_ISO" NVARCHAR(3)," WEEK_NUM" NVARCHAR(2)," MONTH_ID" NVARCHAR(6)," MONTH_CAPTION" NVARCHAR(9)," DAY_OF_CAL_MONTH" NVARCHAR(2)," MONT_OF_YEAR" INTEGER," MONTH_OF_QUARTER" NVARCHAR(1)," CALENDAR_MONTH_NAME" NVARCHAR(9)," MONTH_NAME_SHORT_NO" NVARCHAR(4)," MONTH_DAYS_IN" " MONTH_START_DATE" DATE," MONTH_END_DATE" DATE," QUARTER_ID" NVARCHAR(5)," QUARTER_CAPTION" NVARCHAR(7)," DAY_OF_CAL_QUARTER" NVARCHAR(2)," QUARTER_NUM" NVARCHAR(1)," QUARTER_START_DATE" DATE," QUARTER_END_DATE" DATE," QUARTER_DESCRIPTIONS" TVARTER(14) NVARCHAR(2)," QUARTER_TIME_SPAN" NVARCHAR(2)," YEAR_ID" NVARCHAR(4)," YEAR_CAPTION" NVARCHAR(4)," YEAR_START_DATE" DATE," YEAR_END_DATE" DATE," YEAR_TIME_SPAN" NVARCHAR(10))语言SQLSCRIPT 以安全方式调用,返回" DAY_ID"," UNIX_TIME"," DAY_CAPTION"," DAY_OF_CAL_YEAR"," DAY_OF_CAL_WEEK"," DAY_OF_WEEK"," DAY_NAME_ENG"," DAY_NAME_SHORT_ENG"," DAY_NAME_NOR"," DAY_NAME" " DAY_LAST_DAY_WEEK"," DAY_JULIAN_DATE"," WORKDAY_NOR"," WORKDAY_ENG"," WORKDAY_FREE_1"," WORKDAY_FREE_2"," DAY_TYPE_NOR"," DAY_COMPARABLE_LASTYEAR"," WEEK_ID"," WEEK_CAPTION"," WEEK_NUMTION"," "," MONTH_CAPTION"," DAY_OF_CAL_MONTH"," MONT_OF_YEAR"," MONTH_OF_QUARTER"," CALENDAR_MONTH_NAME"," MONTH_NAME_SHORT_NO"," MONTH_DAYS_IN_MONTH", " MONTH_START_DATE"," MONTH_END_DATE"," QUARTER_ID"," QUARTER_CAPTION"," DAY_OF_CAL_QUARTER"," QUARTER_NUM"," QUARTER_START_DATE"," QUARTER_END_DATE"," QUARTER_DESCRIPTION"," QUARTER_S"," QUARTER_S" "," YEAR_START_DATE"," YEAR_END_DATE"," YEAR_TIME_SPAN"来自" test_db.db :: test.Entity_LOAD_DATE" WHERE DAY_ID <= current_date AND YEAR_ID = TO_NVARCHAR(CURRENT_DATE,'YYYY'); END;
想知道为什么HANA已经提供了自己的时间维度表的原因。 关于第4步:对于任何必需的克隆视图而言,的参数是什么? 为什么不仅仅通过联接来限制呢? 将行作为输入参数传递给另一个计算。 视图是不可能的。 朝着这个方向发展的事情就是您拥有一个带有表格输入的表函数,该函数接收来自步骤3的行,然后可以在SQLScript逻辑中使用这些行来过滤步骤4的数据。
一周热门 更多>