SELECT
CONVERT(varchar(10),t5.FDate,120)AS '日期' ,
t5.FBillNo AS '订单编号',
t4.FName AS '客户名称',
t6.fallamount AS '订单金额',
t1.fallamount AS '开票金额',
t2.FDate AS '发票',
t3.FPreAmountFor AS '预收款',
t3.FAmountFor AS '现金',
t8.FName AS '制单人',
t6.FAmount-t3.FPreAmountFor-t3.FPreAmountFor as '余额',
t6.FInterID,
t4.FItemID
FROM
ICSaleEntry t1,
ICSale t2,
t_RP_NewReceiveBill t3,
t_Organization t4,
SEOrder t5,
SEOrderEntry t6,
--dbo.t_rp_Exchange t7
dbo.t_User t8,
dbo.t_Department t9,
dbo.t_Currency t10
where
t1.FOrderInterID=t5.FInterID
AND t2.FInterID=t1.FInterID
AND t5.FInterID=t6.FInterID
AND t5.FCustID=t4.FItemID
AND t3.fexplanation=t2.fnote
--AND t3.FBillID=t7.FBillID
AND t3.FPreparer=t8.FUserID
and t9.fitemId=t5.FDeptID
and t10.FCurrencyID=t5.FCurrencyID
AND t5.FInterID=t6.FInterID
AND t5.FCustID=t4.FItemID
查询FBillNo订单编号的结果有重复的,但是我只要显示一条出来,请问要把这条语句改成什么样子?
你这个还真不好说啊,而且你的语句也太那个了,这么多表最起码应该有关联表关联字。
1、 可以用排重关键字 distinct 来排重。
2、用左右关联来指定主从表,逻辑上滤掉数据 left outer join、right outer join
你的那些表的关系一点介绍都没有,别人很难帮你找到问题!
试试这样吧!!
--------------------------
SELECT distinct
CONVERT(varchar(10),t5.FDate,120)AS '日期' ,
t5.FBillNo AS '订单编号',
t4.FName AS '客户名称',
t6.fallamount AS '订单金额',
t1.fallamount AS '开票金额',
t2.FDate AS '发票',
t3.FPreAmountFor AS '预收款',
t3.FAmountFor AS '现金',
t8.FName AS '制单人',
t6.FAmount-t3.FPreAmountFor-t3.FPreAmountFor as '余额',
t6.FInterID,
t4.FItemID
FROM
ICSaleEntry t1,
ICSale t2,
t_RP_NewReceiveBill t3,
t_Organization t4,
SEOrder t5,
SEOrderEntry t6,
--dbo.t_rp_Exchange t7
dbo.t_User t8,
dbo.t_Department t9,
dbo.t_Currency t10
where
t1.FOrderInterID=t5.FInterID
AND t2.FInterID=t1.FInterID
AND t5.FInterID=t6.FInterID
AND t5.FCustID=t4.FItemID
AND t3.fexplanation=t2.fnote
--AND t3.FBillID=t7.FBillID
AND t3.FPreparer=t8.FUserID
and t9.fitemId=t5.FDeptID
and t10.FCurrencyID=t5.FCurrencyID
AND t5.FInterID=t6.FInterID
AND t5.FCustID=t4.FItemID
对于重复数据的查询,可能有两种情况,部分重复和完全重复。您的这种情况开应该属于后者.
参考处理办法:http://www.cnblogs.com/jianlinglo/archive/2009/03/07/1405355.html
如果楼主能够把查询的错误结果贴出来就更好了!