有關日期查詢的出貨月報 |
答題得分者是:l630521
|
fuudy
一般會員 發表:30 回覆:11 積分:8 註冊:2002-11-22 發送簡訊給我 |
我有一個等程式,是打印出貨月報的,edtcustno輸入的是客戶號,combobox1輸入的是年份,combobox2輸入的是月份,然後執行查詢,但是我對日期查詢卻不能實現,它總是提示語法錯誤,不知爲何,謝謝!!
var
str,str1,str2,str3:string;
begin
if (combobox2.Text <>'12') and (combobox2.Text <>'10') and (combobox2.Text <>'8') and (combobox2.Text <>'7') and (combobox2.Text <>'5') and (combobox2.Text <>'3') and (combobox2.Text <>'1') then
begin
str:=concat(combobox1.Text,'-',combobox2.Text);
str1:=concat(str,'-','1');
str2:=concat(str,'-','30');
end
else
begin
str:=concat(combobox1.Text,'-',combobox2.Text);
str1:=concat(str,'-','1');
str2:=concat(str,'-','31');
end;
shipreportfrm.adoquery1.close;
shipreportfrm.ADOQuery1.SQL.Clear ;
shipreportfrm.ADOQuery1.SQL.Add('select * from ship');
if edtcustno.Text <>'' then
shipreportfrm.ADOQuery1.SQL.Add('where cust_no =''' edtcustno.text '''') ;
if combobox1.Text <>'' then
shipreportfrm.ADOQuery1.SQL.Add('and ship_date >=:''' str1 '''' );
if combobox2.text<>'' then
shipreportfrm.ADOQuery1.SQL.Add('and ship_date <=:''' str2 '''');
shipreportfrm.ADOQuery1.Open ;
shipprintfrm.Close ;
if shipreportfrm.adoquery1.RecNo >=1 then
shipreportfrm.QuickRep1.Preview
else
messagebox(0,'error','information',MB_OK);
end;
|
l630521
資深會員 發表:15 回覆:349 積分:372 註冊:2003-02-17 發送簡訊給我 |
|
fuudy
一般會員 發表:30 回覆:11 積分:8 註冊:2002-11-22 發送簡訊給我 |
|
l630521
資深會員 發表:15 回覆:349 積分:372 註冊:2003-02-17 發送簡訊給我 |
fuudy兄!
請問你對日期查詢時有沒有輸入客戶號?因為你的where寫在客戶號的查詢裡,如果你有有輸入客戶號的話,SQL語法就少了where了!
另外在日期部份的話,是否可用Year() 和 Month()的函數來比對,而不要加入完整之日期
if combobox1.Text <>'' then
shipreportfrm.ADOQuery1.SQL.Add(' and Year(ship_date) =' combobox1.text);
if combobox2.text<>'' then
shipreportfrm.ADOQuery1.SQL.Add(' and Month(ship_date) =' combobox2.text);
再不行的話,請你用ShowMessage(shipreportfrm.ADOQuery1.SQL.Text)看一下SQL語法為何! Ian
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |