繁体   English   中英

我无法使用此 SQL 语句按开始日期和结束日期字段过滤表

[英]I am having trouble getting this SQL statement to filter the table by a starting date and ending date field

我无法使用此 SQL 语句按开始日期和结束日期字段过滤表。 所有字段都在同一个表中,我不确定我是否制定了错误的内容......我显然是 SQL 新手,提前感谢您提供的任何帮助。

ExecuteSQL (
"
SELECT sum (Billing_Tab_Hours_Total_1 
+ Billing_Tab_Hours_Total_2
+ Billing_Tab_Hours_Total_3
+ Billing_Tab_Hours_Total_4
+ Billing_Tab_Hours_Total_5
+ Billing_Tab_Hours_Total_6
+ Billing_Tab_Hours_Total_7
+ Billing_Tab_Hours_Total_8
+ Billing_Tab_Hours_Total_9
+ Billing_Tab_Hours_Total_10)
FROM TABLE
WHERE Billing_Tab_Name_1 = 'Employee Name'
OR Billing_Tab_Name_2 = ‘Employee Name’
OR Billing_Tab_Name_3 = 'Employee Name'
OR Billing_Tab_Name_4 = 'Employee Name'
OR Billing_Tab_Name_5 = 'Employee Name'
OR Billing_Tab_Name_6 = 'Employee Name'
OR Billing_Tab_Name_7 = 'Employee Name'
OR Billing_Tab_Name_8 = 'Employee Name'
OR Billing_Tab_Name_9 = 'Employee Name'
OR Billing_Tab_Name_10 = 'Employee Name'
AND Billing_Tab_Date_1 BETWEEN Report_Starting_Date and        Report_Ending_Date
OR Billing_Tab_Date_2 BETWEEN Report_Starting_Date AND Report_Ending_Date
OR Billing_Tab_Date_3 BETWEEN Report_Starting_Date AND Report_Ending_Date
OR Billing_Tab_Date_4 BETWEEN Report_Starting_Date AND Report_Ending_Date
OR Billing_Tab_Date_5 BETWEEN Report_Starting_Date AND Report_Ending_Date
OR Billing_Tab_Date_6 BETWEEN Report_Starting_Date AND Report_Ending_Date
OR Billing_Tab_Date_7 BETWEEN Report_Starting_Date AND Report_Ending_Date
OR Billing_Tab_Date_8 BETWEEN Report_Starting_Date AND Report_Ending_Date
OR Billing_Tab_Date_9 BETWEEN Report_Starting_Date AND Report_Ending_Date
OR Billing_Tab_Date_10 BETWEEN Report_Starting_Date AND Report_Ending_Date
"
; "" ; "" )

尝试这个:

如果您不关心将 Billing_Tab_name 与 Billing_Tab_hours 匹配,那么您可以使用:

ExecuteSQL ("
SELECT sum (Billing_Tab_Hours_Total_1 
+ Billing_Tab_Hours_Total_2
+ Billing_Tab_Hours_Total_3
+ Billing_Tab_Hours_Total_4
+ Billing_Tab_Hours_Total_5
+ Billing_Tab_Hours_Total_6
+ Billing_Tab_Hours_Total_7
+ Billing_Tab_Hours_Total_8
+ Billing_Tab_Hours_Total_9
+ Billing_Tab_Hours_Total_10)
FROM TABLE
WHERE (Billing_Tab_Name_1 = 'Employee Name'
OR Billing_Tab_Name_2 = ‘Employee Name’
OR Billing_Tab_Name_3 = 'Employee Name'
OR Billing_Tab_Name_4 = 'Employee Name'
OR Billing_Tab_Name_5 = 'Employee Name'
OR Billing_Tab_Name_6 = 'Employee Name'
OR Billing_Tab_Name_7 = 'Employee Name'
OR Billing_Tab_Name_8 = 'Employee Name'
OR Billing_Tab_Name_9 = 'Employee Name'
OR Billing_Tab_Name_10 = 'Employee Name')
AND (Billing_Tab_Date_1 BETWEEN Report_Starting_Date and        Report_Ending_Date
OR Billing_Tab_Date_2 BETWEEN Report_Starting_Date AND Report_Ending_Date
OR Billing_Tab_Date_3 BETWEEN Report_Starting_Date AND Report_Ending_Date
OR Billing_Tab_Date_4 BETWEEN Report_Starting_Date AND Report_Ending_Date
OR Billing_Tab_Date_5 BETWEEN Report_Starting_Date AND Report_Ending_Date
OR Billing_Tab_Date_6 BETWEEN Report_Starting_Date AND Report_Ending_Date
OR Billing_Tab_Date_7 BETWEEN Report_Starting_Date AND Report_Ending_Date
OR Billing_Tab_Date_8 BETWEEN Report_Starting_Date AND Report_Ending_Date
OR Billing_Tab_Date_9 BETWEEN Report_Starting_Date AND Report_Ending_Date
OR Billing_Tab_Date_10 BETWEEN Report_Starting_Date AND Report_Ending_Date)
"; "" ; "" )

但是如果他们必须匹配,那么你需要这个:

ExecuteSQL ("
SELECT sum (Billing_Tab_Hours_Total_1 
+ Billing_Tab_Hours_Total_2
+ Billing_Tab_Hours_Total_3
+ Billing_Tab_Hours_Total_4
+ Billing_Tab_Hours_Total_5
+ Billing_Tab_Hours_Total_6
+ Billing_Tab_Hours_Total_7
+ Billing_Tab_Hours_Total_8
+ Billing_Tab_Hours_Total_9
+ Billing_Tab_Hours_Total_10)
FROM TABLE
WHERE (Billing_Tab_Name_1 = 'Employee Name' AND Billing_Tab_Date_1 BETWEEN Report_Starting_Date and        Report_Ending_Date)
OR (Billing_Tab_Name_2 = ‘Employee Name’ AND Billing_Tab_Date_2 BETWEEN Report_Starting_Date AND Report_Ending_Date)
OR (Billing_Tab_Name_3 = 'Employee Name' AND Billing_Tab_Date_3 BETWEEN Report_Starting_Date AND Report_Ending_Date)
OR (Billing_Tab_Name_4 = 'Employee Name' AND Billing_Tab_Date_4 BETWEEN Report_Starting_Date AND Report_Ending_Date)
OR (Billing_Tab_Name_5 = 'Employee Name' AND Billing_Tab_Date_5 BETWEEN Report_Starting_Date AND Report_Ending_Date)
OR (Billing_Tab_Name_6 = 'Employee Name' AND Billing_Tab_Date_6 BETWEEN Report_Starting_Date AND Report_Ending_Date)
OR (Billing_Tab_Name_7 = 'Employee Name' AND Billing_Tab_Date_7 BETWEEN Report_Starting_Date AND Report_Ending_Date)
OR (Billing_Tab_Name_8 = 'Employee Name' AND Billing_Tab_Date_8 BETWEEN Report_Starting_Date AND Report_Ending_Date)
OR (Billing_Tab_Name_9 = 'Employee Name' AND Billing_Tab_Date_9 BETWEEN Report_Starting_Date AND Report_Ending_Date)
OR (Billing_Tab_Name_10 = 'Employee Name' AND Billing_Tab_Date_10 BETWEEN Report_Starting_Date AND Report_Ending_Date) 
"; "" ; "" )

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM