读书人

这个SQL中报一个异常如何修改正确呢

发布时间: 2012-10-11 10:16:10 作者: rapoo

这个SQL中报一个错误,怎么修改正确呢?先谢谢帮忙的人!
select

dg.chr_deliver_date as chr_back_ymd,--日期

'发货' as State_One,--摘要(状态)

dd.chr_product_name as chr_product_name,--产品型号(产品名)

dd.chr_bill_count as chr_bill_count,--数量

dd.chr_bill_price as chr_bill_price,--单价

dd.chr_serial_no as chr_fapiao_no,--发票号

dd.billmoney as chr_bill_money,--发货金额

'' as chr_pay_cash,--回款

'' as chr_back_ymd1--欠款(需统计加减)

from tt_deliver_goods_tbl as dg--发货表

left join (
select tm_product_tbl.chr_product_name,dd1.chr_dingdan_no,dd1.chr_bill_count,dd1.chr_bill_price,
dd1.chr_serial_no,COALESCE(dd1.chr_bill_money,0) as billmoney

from tt_dingdan_detail_tbl as dd1

left join tm_product_tbl

on tm_product_tbl.chr_product_id=dd1.chr_product_id

)as dd -----订单详细表

on dg.chr_dingdan_no =dd.chr_dingdan_no

order by chr_back_ymd

-----
union all
------
select

tc.chr_done_date as chr_back_ymd,--日期

'上单结转' as State_One,--摘要(状态)

'' as chr_product_name,--产品型号(产品名)

'' as chr_bill_count,--数量

'' as chr_bill_price,--单价

'' as chr_fapiao_no,--发票号

'' as chr_bill_money,--发货金额

'' as chr_pay_cash,--回款

tc.chr_cash_before as chr_back_ymd--欠款(需统计加减)

from tt_customer_bank_tbl as tc --客户账户表

where '2012-10-01' > chr_done_date

and int_nub_no in (

select max(int_nub_no) from tt_customer_bank_tbl

group by chr_customer_id

) order by int_nub_no desc



[解决办法]
去掉order by
[解决办法]
你是sql 2000吧?
Order by不能直接在union子句中使用

[解决办法]
你google搜索下

关键字

order by union

里面有解决方法

读书人网 >VB Dotnet

热点推荐