#i have two tables buyers table and sales table#
购买者表
|买家|平衡|
销售表
|买家|销售|购买日期|
我尝试了以下选择查询
Dim connection As OleDbConnection
Dim adapter As OleDbDataAdapter
Dim ds As New DataSet
Dim SQLStr As String
Dim cmd As OleDbCommand
connection = New
OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=consignacion.mdb;")
SQLStr = "SELECT b.buyer as [Buyer],b.balance as
[Balance],SUM(s.total) as [Sales],
b.balance+SUM(s.total) as [Total] From buyerdb b
INNER Join salesdb s on b.buyer=s.buyer
WHERE s.total Is Not NULL And
s.buydate =@buydate And
s.total<>@sales AND
b.balance> @balance
GROUP By b.buyer,b.balance"
SQLStr = "SELECT b.buyer as [Buyer],b.balance as
[Balance],SUM(s.total) as [Sales],
b.balance+SUM(s.total) as [Total] From buyerdb b
INNER Join salesdb s on b.buyer=s.buyer
WHERE s.total Is Not NULL And
s.buydate =@buydate And s.total<>@sales AND b.balance> @balance
GROUP By b.buyer,b.balance"
cmd = New OleDbCommand(SQLStr, connection)
cmd.Parameters.AddWithValue("@buydate", Form1.Lbldate2.Text)
cmd.Parameters.AddWithValue("@balance", 0)
cmd.Parameters.AddWithValue("@sales", "")
I expect the output to be buyer balance sales total CESS 350 984 1334 DARWIN 0 345 345 GLEN 1000 4334 5334 GLENDA 0 170 170 JOSE 1000 2240 3240 LITO 0 120 120 LOUIE 0 280 280 TANIS 0 2250 2250 YOLLY 1500 832 2332 michael 1500 [null/norecor] 1500 Dudice 700 [null/norecord] 700 but the output is
买方余额销售总额
CESS 350 84 334
> DARWIN 0 345 345
> GLEN 1000 4334 5334
> GLENDA 0 170 170
> JOSE 1000 2240 3240
> LITO 0 120 120
> LOUIE 0 280 280
> TANIS 0 2250 2250
> YOLLY 1500 832 2332
它没有显示有余额的买方,但是在给定购买日期没有记录的销售额
我已经尽力了。我什至搜索google和youtube,而且似乎无法在我的数据网格视图上获得正确的输出。
答案 0 :(得分:0)
如果我要求您向我展示一些不存在的东西,那么您就不能,因为它不存在。数据库中的NULL相同。它们表示不存在某些内容,因此数据库无法向您显示任何内容。
您可以做的是使用ISNULL语句将NULLS替换为实际值。尝试像这样更改您的选择语句:
SELECT b.buyer as [Buyer],b.balance as
[Balance],SUM(ISNULL(s.total,0)) as [Sales] .........
这会将s.total中的所有NULL替换为0。