全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1029
推到 Plurk!
推到 Facebook!

SQL指令問題!

尚未結案
Vashee
初階會員


發表:38
回覆:87
積分:25
註冊:2003-03-31

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-04-11 07:30:02 IP:217.34.xxx.xxx 未訂閱
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

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-04-11 09:43:43 IP:147.8.xxx.xxx 未訂閱
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

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-04-11 14:05:54 IP:217.36.xxx.xxx 未訂閱
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

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-04-11 14:23:59 IP:147.8.xxx.xxx 未訂閱
引言: 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

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-04-11 15:39:30 IP:217.36.xxx.xxx 未訂閱
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

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-04-11 16:19:22 IP:147.8.xxx.xxx 未訂閱
Using a TDBEdit as I suggested before should work... If you want to use a TEdit, then: Edit1.Text := Query1.Fields[1].AsString;
Vashee
初階會員


發表:38
回覆:87
積分:25
註冊:2003-03-31

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-04-11 16:46:55 IP:217.36.xxx.xxx 未訂閱
.Fields[1].AsString; <---- what's this bit means? can u explain?
Vashee
初階會員


發表:38
回覆:87
積分:25
註冊:2003-03-31

發送簡訊給我
#8 引用回覆 回覆 發表時間:2003-04-11 16:53:52 IP:217.36.xxx.xxx 未訂閱
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

發送簡訊給我
#9 引用回覆 回覆 發表時間:2003-04-11 16:55:39 IP:217.36.xxx.xxx 未訂閱
Final Finaly how can I print stuff using Query??
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#10 引用回覆 回覆 發表時間:2003-04-11 17:15:33 IP:147.8.xxx.xxx 未訂閱
引言:.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

發送簡訊給我
#11 引用回覆 回覆 發表時間:2003-04-11 17:37:28 IP:217.36.xxx.xxx 未訂閱
can Rave relate use of Query as well? can u teach me??
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#12 引用回覆 回覆 發表時間:2003-04-11 17:51:34 IP:147.8.xxx.xxx 未訂閱
引言: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...
系統時間:2024-07-01 9:11:59
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!