begin
//日
if Indx=0 then
begin
SQLStr:=SQLStr+'where '+LUFieldName+' = To_Date('+
''''+FormatDateTime('yyyy-mm-dd',dtLUDate.Date)
+''''+','+''''+'yyyy-mm-dd'+''')';
end;
//月
if Indx=1 then
begin
SQLStr:=SQLStr+' and '+LUFieldName+' Between To_Date('+
''''+FormatDateTime('yyyy-mm',dtLUDate.Date)+'-01'+''''+','+
''''+'yyyy-mm-dd'+''''+')'+
' and To_Date('+
''''+FormatDateTime('yyyy-mm',dtLUDate.Date)+
IntToStr(DaysInMonth(dtLUDate.Date))+''+''''+','+
''''+'yyyy-mm-dd'+''''+')';
end;
//年
if Indx=2 then
begin
SQLStr:=SQLStr+' and '+LUFieldName+' Between To_Date('+
''''+FormatDateTime('yyyy',dtLUDate.Date)+'-01-01'+''''+','+
''''+'yyyy-mm-dd'+''''+')'+
' and To_Date('+
''''+FormatDateTime('yyyy',dtLUDate.Date)+'-12-31'+''''+','+
''''+'yyyy-mm-dd'+''''+')';
end;
这是代码的一部分,是根据年或月或日查询,为什么根据年和月查询时提示:语句为正确结束。
谢谢各位了
//日
if Indx=0 then
begin
SQLStr:=SQLStr+'where '+LUFieldName+' = To_Date('+
''''+FormatDateTime('yyyy-mm-dd',dtLUDate.Date)
+''''+','+''''+'yyyy-mm-dd'+''')';
end;
//月
if Indx=1 then
begin
SQLStr:=SQLStr+' and '+LUFieldName+' Between To_Date('+
''''+FormatDateTime('yyyy-mm',dtLUDate.Date)+'-01'+''''+','+
''''+'yyyy-mm-dd'+''''+')'+
' and To_Date('+
''''+FormatDateTime('yyyy-mm',dtLUDate.Date)+
IntToStr(DaysInMonth(dtLUDate.Date))+''+''''+','+
''''+'yyyy-mm-dd'+''''+')';
end;
//年
if Indx=2 then
begin
SQLStr:=SQLStr+' and '+LUFieldName+' Between To_Date('+
''''+FormatDateTime('yyyy',dtLUDate.Date)+'-01-01'+''''+','+
''''+'yyyy-mm-dd'+''''+')'+
' and To_Date('+
''''+FormatDateTime('yyyy',dtLUDate.Date)+'-12-31'+''''+','+
''''+'yyyy-mm-dd'+''''+')';
end;
这是代码的一部分,是根据年或月或日查询,为什么根据年和月查询时提示:语句为正确结束。
谢谢各位了
================================
严重同意
但是这样在月和日的查询的时候会不会出问题?
还有就是''''这个看起来太麻烦了建议你用#39来代替。我都是这么做的。
比如查 2004 的
YearStr='2004';MonthStr='%';Datestr='%'
查 2004-01 的
YearStr='2004';MonthStr='01';Datestr='%'s:=format('where convert(char(12),orderdate,120) like '''+%s-%s-%s'''',[YearStr,MonthStr,Datestr]);