简体   繁体   中英

How can I maintain a stock report using Crystal Reports?

I want to take the following result with the help of query in Crystal Reports:

I have a stock table where three column's "type", "product", and "quantity" now I want that to drag two sql expressions in my report 1st is "INN" and 2nd is "Out" and it comes like if the "type" is purchase so it check the "product" field and ADD the quantity and if the type is Sale it less the quantity acording to "product"

So what query should I write to get the result?

You have a table with a type field. Given your question there are some things one can only assume to answer it. So I assume:
1. type is of the type smallint
2. it is 1 for purchases or receipts and 2 for sales or deliveries
3. you mean you need to know the final stock of products
Then the query is:
select product, sum((3-2*type)*quantity) as stock from table_name group by product

if you have other values for types you will have to use different formula than 3-2*type. Good luck

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM