创建一个公式,将1个varchar字段w / date和1个varchar w / time转换为1个datetime字段

时间:2018-04-27 22:00:27

标签: crystal-reports

我有一个包含2个Form hi = new Form("Hi World", BoxLayout.y()); // Warning: you need to set the theme property "ComponentGroupBool" to true Button button1 = new Button("Button 1", "ButtonMenuCategories"); CheckBox button11 = CheckBox.createToggle("Button 1.1"); CheckBox button12 = CheckBox.createToggle("Button 1.2"); Button button13 = new Button("Button 1.3", "ButtonMenuCategories"); CheckBox button131 = CheckBox.createToggle("Button 1.3.1"); CheckBox button132 = CheckBox.createToggle("Button 1.3.2"); CheckBox button133 = CheckBox.createToggle("Button 1.3.3"); CheckBox button14 = CheckBox.createToggle("Button 1.4"); Button button2 = new Button("Button 2", "ButtonMenuCategories"); Button button3 = new Button("Button 3", "ButtonMenuCategories"); Button button4 = new Button("Button 4", "ButtonMenuCategories"); Button button5 = new Button("Button 5", "ButtonMenuCategories"); Accordion accordion13 = new Accordion(); accordion13.addContent(button13, FlowLayout.encloseCenter(ComponentGroup.enclose(button131, button132, button133))); Accordion accordion1 = new Accordion(); accordion1.addContent(button1, FlowLayout.encloseCenter(ComponentGroup.enclose(button11, button12, accordion13, button14))); Accordion accordion2 = new Accordion(); accordion2.addContent(button2, new Label("Hello")); Accordion accordion3 = new Accordion(); accordion3.addContent(button3, new Label("Hello")); Accordion accordion4 = new Accordion(); accordion4.addContent(button4, new Label("Hello")); Accordion accordion5 = new Accordion(); accordion5.addContent(button5, new Label("Hello")); Container menu = FlowLayout.encloseCenter(ComponentGroup.enclose(accordion1, accordion2, accordion3, accordion4, accordion5)); hi.add(menu); hi.show(); 字段的现有报告。 1持有日期,2持有时间。我需要创建一个连接两者的公式,然后使用该公式对报表进行排序。示例:

varchar

我想将两个字段一起添加然后排序。 在SQL中,我可以执行以下操作,但在水晶报表中,它无法正确转换并引发错误。

SCHEDULED_DATE             SCHEDULED_TIME
2018-04-26 00:00:00.000    1:00 PM
2018-04-26 00:00:00.000    NULL

以下是我对Crystal Report公式的尝试:

ORDER BY Convert(Datetime, SCHEDULED_DATE + Convert(time,ISNULL(SCHEDULED_TIME, '00:00:00.000')))

非常感谢任何帮助。 感谢

1 个答案:

答案 0 :(得分:0)

首先,日期和时间值不应存储为文本。
更好地使用DBMS的相应数据类型。

然后在公式中看到多个问题:

  • @echo off for /f "usebackq tokens=*" %%a in (`powershell -command " ' one two ' "`) do echo Result is "%%a" Result is "one two " 不支持毫秒
  • CDateCDateTime值无法与Date
  • 连接
  • Time - 列已包含时间部分,您(尝试)再添加一个
  • 连接日期和时间部分时,请用空格分隔

因此,您必须删除时间部分并连接列,而不将其转换为+SCHEDULED_DATE

Date

注意:我完全删除了" True" -part中的时间Time,因为无论如何都不需要全部为零。