計算欄位問題,急!!! |
尚未結案
|
goodstone
一般會員 發表:8 回覆:2 積分:2 註冊:2003-05-30 發送簡訊給我 |
我想在庫存dbgrid中秀出金額,而單價是存在price表中的unitprice欄位,
用select a.*,b.unitprice,a.stockqty*b.unitprice as stockmoney from
stock a left join price b on(a.matename=b.matename and a.matesp=b.matesp and a.mateclass=b.mateclass )
問韙是:兩表關聯的鍵:matename+matesp+mateclss存在matesp和mateclass為空的狀況,只能得到matename,matesp,mateclass都不為空的價格。
price表:
matename matesp mateclass unitprice
a 10
b b 20
c c c 30
stock表:
matename matesp mateclass stockqty
a 200
b b 300
c c c 400
結果只是:
matename matesp mateclass unitprice stockqty
a 0 0
b b 0 0
c c c 30 12000
請問怎樣寫可出得到
matename matesp mateclass unitprice stockqty
a 10 2000
b b 20 6000
c c c 30 12000
|
timhuang
尊榮會員 發表:78 回覆:1815 積分:1608 註冊:2002-07-15 發送簡訊給我 |
|
azurecloud
中階會員 發表:52 回覆:108 積分:92 註冊:2003-09-04 發送簡訊給我 |
Hi,goodstone 您好:
在 SQL 語法中 Null 不代表 "任何值" 也可以說 "不知道它是什麼值",
所以 Null = Null 是不成立的,問頭出在這裡
(a.matename=b.matename and a.matesp=b.matesp and a.mateclass=b.mateclass ) 對於您的問題,可參考以下處理
一、
select isnull(matename,'n/a') as matename,isnull(matesp,'n/a') as matesp,isnull(mateclass,'n/a') as mateclass,isnull(unitprice,0) as unitprice
into temptable from price select isnull(matename,'n/a') as matename,isnull(matesp,'n/a') as matesp,isnull(mateclass,'n/a') as mateclass,isnull(stockqty,0) as stockqty
into temptable1 from stock
二、以 temptable,temptable1 當成 DBgrid 的來源資料表
三、做完後下 Drop table temptable,temptable1 希望幫得上忙
|
goodstone
一般會員 發表:8 回覆:2 積分:2 註冊:2003-05-30 發送簡訊給我 |
|
chih
版主 發表:48 回覆:1186 積分:639 註冊:2002-04-02 發送簡訊給我 |
1.如你最後的畫面語法應該是這樣..
用select a.*,b.unitprice,a.stockqty*b.unitprice as stockmoney from
stock a left join price b on(a.matename=b.matename )
2.如果你確定Select條件是這樣沒有錯的話..
select a.*,b.unitprice,a.stockqty*b.unitprice as stockmoney from
stock a left join price b on(a.matename=b.matename and a.matesp=b.matesp and a.mateclass=b.mateclass )
那你應該將 matename,matesp,mateclass 都設為Key值並且不得為空白,這樣存入後再Select 出來就會有你要的畫面了..
TRY TRY SEE..
>
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |