我有一个在 vb.net 中使用的当前 sql 查询,以获取一些返回到 datagridview 的数据。我正在检查日期时间选择器的年、月和日期,以获取从所选表返回的必要信息。我的查询工作正常,减去 case 语句部分来检查特定日期。谁能帮我解决这个查询或建议一种替代方法?
"SELECT * FROM " & Me.SelectedTable.SelectedItem.ToString & "
WHERE(Datepart(yyyy," & colName & ") BETWEEN '" & Me.DateTimePicker1.Value.Year & "' AND '" & Me.DateTimePicker2.Value.Year & "'
AND Datepart(mm," & colName & ") BETWEEN '" & Me.DateTimePicker1.Value.Month & "' AND '" & Me.DateTimePicker2.Value.Month & "'
AND Datepart(dd," & colName & ") <= " & Me.DateTimePicker1.Value.Day
& " CASE WHEN Datepart(mm," & colName & ")=" & Me.DateTimePicker1.Value.Month & "
THEN Datepart(dd," & colName & ") = " & Me.DateTimePicker1.Value.Day & "
WHEN Datepart(mm," & colName & ")= " & Me.DateTimePicker2.Value.Month
& " Datepart(dd," & colName & ")= " & Me.DateTimePicker2.Value.Day & "
ELSE Datepart(dd," & colName & ") BETWEEN 1 AND 31 END)"