|
SELECT CUR_STOCK.DEPART ,
CUR_STOCK.CODE ,
(SELECT CASE WHEN ISNULL(CUR_STOCK.BARCODE,"") = "" THEN MAX(BARCODE) ELSE CUR_STOCK.BARCODE END
FROM COMM_BARCODE WHERE COMM_BARCODE.CODE = CUR_STOCK.CODE ) AS BARCODE,
" "+COMMODITY.NAME + (case when spec = null or spec = "" then "" else "["+commodity.spec +"]" end ) as name,
COMMODITY.UNIT,
COMMODITY.CONVERSION,
sum(CUR_STOCK.AMOUNT) as amount,
sum(CUR_STOCK.SUM_COST) / sum(CUR_STOCK.AMOUNT) as costprice,
sum(CUR_STOCK.SUM_COST) as sum_cost,
sum(CUR_STOCK.SUM_COST * 100 / (100 + isnull(commodity.incometax,0))) as sum_wscost,
commodity.price as price,
sum(CUR_STOCK.AMOUNT * commodity.price) as sum_price ,
(SELECT MIN(SPEC_PRICE) FROM POP_INFO WHERE CODE = CUR_STOCK.CODE AND DEPART = CUR_STOCK.DEPART AND
ENDDATE>DATEADD(DD,-1,GETDATE())) as spec_price
FROM CUR_STOCK , COMMODITY
WHERE (commodity.sort like "10503008%" ) and CUR_STOCK.CODE = COMMODITY.CODE AND COMMODITY.NATURE not like "联营%"
and (COMMODITY.ifstock = 1 or (commodity.ifstock = 0 and depart in (select code from depart where nature = "s2")))
and cur_stock.depart not in (select code from operator_fun where operator = :as_op_depart and type = "部门" group by code)
and commodity.sort not in (select code from operator_fun where operator = :as_op_depart and type = "类别" group by code)
AND CUR_STOCK.acctype LIKE :as_taxtype
GROUP BY CUR_STOCK.DEPART , CUR_STOCK.CODE ,CUR_STOCK.BARCODE,commodity.name,commodity.spec,COMMODITY.UNIT,commodity.price,COMMODITY.CONVERSION
Having sum(CUR_STOCK.AMOUNT)<>0 |
|