Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to generate a column in cursor

Status
Not open for further replies.

alisaif

ISP
Apr 6, 2013
418
AE
Hi,

How can I generate a column in a cursor which can count the no of records in Sales Order using sql-select command.

Sales Order
-----------

1. Sono
2. date
3. icode
5. quantity
6. rate

And, I want is :

1. sono
2. date
3. totitem ( want to generate this column which can count the total records of each sales order ).

Thanks

Saif
 
Does GROUP BY and aggregation functions COUNT,SUM,AVG,MIN,MAX... ring a bell?
Does expression AS fieldname ring a bell?

Code:
SELECT sono, date, COUNT(*) AS totitem FROM yourtable GROUP BY sono,date

Bye, Olaf.
 
... I'm rather sure you need more than just the count of records, you need to sum the quantities. Also unsure what icode is, could be an order item ID, simply a sequential number, but might also be a product code. After explaining each field involved, you get better advice. Sono is esperanto for sound, I'm quite sure it has another meaning. So you better have a system documentation telling the meaning of fields, as at least some are not self explanatory.

Bye, Olaf.
 
Thanks Mr.Olaf

It is perfect

SELECT sono, date, COUNT(*) AS totitem FROM yourtable GROUP BY sono,date

It serves my purpose, I just need total records of each order.

Thanks

Saif
 
Olaf,

I SUSPECT, but am not sure, that sono means Sales Order Number and icode means Item Code.

You are correct in suggesting that the OP should be clearer both to us and to anyone who may need to modify his code in the future.

mmerlinn


Poor people do not hire employees. If you soak the rich, who are you going to work for?

"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Raymond
 
Hi

I SUSPECT, but am not sure, that sono means Sales Order Number and icode means Item Code.

Yes it is correct. I got my answer.

Thanks

Saif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top