SQL指令問題! |
尚未結案
|
Vashee
初階會員 發表:38 回覆:87 積分:25 註冊:2003-03-31 發送簡訊給我 |
From the past I have been trying to get this solution by SQL, but I couldn't find or figure the solution using SQL. From my understanding, SQL is given constraint or instruction within field inside database structure, but I can't figure how to output things into Delphi components. May be there is but I just can't not figure it out
|
william
版主 發表:66 回覆:2535 積分:3048 註冊:2002-07-11 發送簡訊給我 |
I think you should use data-aware components, e.g. TDBEdit instead of TEdit. In your case since the fields are unknow until the query is executed (or you can add type fields to the query ), class="code">
DBEdit1.Datasource := DataSource1;
DBEdit1.DataField.FieldName := Query1.Fields[0].FieldName;
|
Vashee
初階會員 發表:38 回覆:87 積分:25 註冊:2003-03-31 發送簡訊給我 |
and I found alternative approach using Delphi:
procedure TOrderSytem.QtnEditExit(Sender: TObject);
var value1, value2 : real;
begin
tTempShow.Append;
tTempShow.FieldByName('DishID').Value := tSearch.FieldValues['ID'];
tTempShow.FieldByName('DishName').Value := tSearch.FieldValues['DishName'];
tTempShow.FieldByName('Quantity').Value := Qtnedit.Text;
value1 := tSearch.fieldValues['Price'];
value2:= tTempShow.FieldValues['quantity'] * value1;
tTempShow.FieldValues['Subtotal'] := value2;
tTempShow.Post;
end; It works for calculating subtotal, but!
I can work out the total:
Is there a Sum(Whole Column) of table using Delphi syntex?? Urgent! Plz help!!
|
william
版主 發表:66 回覆:2535 積分:3048 註冊:2002-07-11 發送簡訊給我 |
引言: Is there a Sum(Whole Column) of table using Delphi syntex??The simplest way is to execute a SQL statement and get the sum. For table (i.e. BDE/ADO table), you need to calculate it yourself. There exists a way in using client dataset and aggregate fields for this kind of caluclation, this is more complicated and I think you should try the SQL way first. |
Vashee
初階會員 發表:38 回覆:87 積分:25 註冊:2003-03-31 發送簡訊給我 |
I have the SQL solution, but I want the output is actually on a Tedit? My sql solution:
select OrderNumber, Sum(Price * Quantity) as OrderTotal
from Detail D, Menu M
where D.FoodID = M.FoodID
group by OrderNumber but I can't output the result on a Tedit, it is always has been my problem.plz plz my lord..
|
william
版主 發表:66 回覆:2535 積分:3048 註冊:2002-07-11 發送簡訊給我 |
|
Vashee
初階會員 發表:38 回覆:87 積分:25 註冊:2003-03-31 發送簡訊給我 |
|
Vashee
初階會員 發表:38 回覆:87 積分:25 註冊:2003-03-31 發送簡訊給我 |
use put this coding in a button using this qTotal query: select D.OrderNumber, Sum(Price * Quantity) as Total
from DetailTable D, Menu M
where D.DishID = M.ID
group by D.OrderNumber with
Edit3.Text := qTotal.Fields[1].AsString; something shows up, but it is '0'
why?
|
Vashee
初階會員 發表:38 回覆:87 積分:25 註冊:2003-03-31 發送簡訊給我 |
|
william
版主 發表:66 回覆:2535 積分:3048 註冊:2002-07-11 發送簡訊給我 |
引言:.Fields[1].AsString; <---- what's this bit means? can u explain?Please refer to the help of TField since xxx.Fields[x] is a TField. 引言:something shows up, but it is '0'Data is 0... Please check by executing the SQL using SQL Explorer. 引言:how can I print stuff using Query??I guess you want a good looking way to print it, right? Perhaps you should try those reporting systems, e.g. Rave Report/Quick Report; they come with Delphi 7. |
Vashee
初階會員 發表:38 回覆:87 積分:25 註冊:2003-03-31 發送簡訊給我 |
|
william
版主 發表:66 回覆:2535 積分:3048 註冊:2002-07-11 發送簡訊給我 |
引言:can Rave relate use of Query as well? can u teach me??Both Rave Report/Quick Report and other report tools are always working on data (i.e. query, table); and it is why they exist. I am sorry I can't help you here since I never use any reporting tools, what I did was do it ALL (query/preview/print) by myself in the past. Try playing with Rave first since Borland seems would like to drop Quick Report... |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |