Click here to Skip to main content
15,905,875 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want output like this

item_type:
Vegetables 
itemNumber  ItemName   quantity   price
101         Potato      10       20.00
102         Tomato     102       10.00
item_type:
Fruits:
itemNumber  ItemName   quantity   price
 103        Mango       2         30.00
 104        Apple       4         40.00


I tried the following query

SQL
select item_number,item_type,item_name ,quantity ,price from purchase_order order by item_type;


but the output is like this

item_number	item_type	item_name	quantity	price
3	   	fruits	         Dates          3	        57.900
6	        fruits		 Jackfruit      34              10.890	
1	        vegetables       Ladies Finger	23	        45.000
3	        vegetables       Broad Beans	23	        53.900



I tried group by clause bt it needs aggregate function

give me an idea how to do get that output
Posted
Updated 8-May-12 0:14am
v2

Query is totally correct! You need to change the order of fields:
SQL
SELECT item_type, item_number, item_name, quantity ,price
FROM purchase_order
ORDER BY item_type


You you want to group records by item_type, you need to use reports to get this functionallity.
Step by Step Creation of Crystal Report using its Features Group, Graph, Cross-Tab and Sub Report[^]
ReportViewer[^]
 
Share this answer
 
Comments
kevin_ze 8-May-12 8:20am    
Thanks,
that crystal report link is very useful to me
Maciej Los 8-May-12 9:03am    
You're welcome ;)
Can you rate my answer?
u create stored procedure send parameter in ur item type and display it.


ALTER PROCEDURE purchase_order
@ItemType string
AS
BEGIN
select itemno, itemname, qualityprice as Balance from PaymentLedger
WHERE ItemType = @ItemType

END
 
Share this answer
 
Comments
kevin_ze 8-May-12 8:19am    
Thank u very much for ur answer...
add group by to item_type so you will get item list according to item_type
 
Share this answer
 
Add the column item_type in both the tables
 
Share this answer
 
here am using single table and column item_type is already there in that table
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900