Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Complicated Query
Message
From
13/05/2008 21:09:52
 
 
To
13/05/2008 03:51:17
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows XP
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01316576
Message ID:
01316870
Views:
11
Dear Professors

Create Cursor table1 ;
(code Char(7), name Char(30), qty n(4), credit N(12), Debit N(12), code2 Char(7))

Insert Into table1 Values ('1401001','Eric',0,0,100,'3201001')
Insert Into table1 Values ('3201001','Apple',10,100,0,'1401001')
Insert Into table1 Values ('1401001','Eric',0,0,200,'3202001')
Insert Into table1 Values ('3202001','Potato',20,200,0,'1401001')

Total qty=30
Amount1=100
Amount1=200

Insert Into table1 Values ('1401002','Boris',0,0,500,'3201003')
Insert Into table1 Values ('3201003','Mango',50,500,0,'1401002')
Insert Into table1 Values ('1401002','Boris',0,0,300,'3202001')
Insert Into table1 Values ('3202001','Juice',20,300,0,'1401002')

Total qty=70
Amount1=500
Amount1=300

The result must be look like this
--code---name-----qty---amt1--amt2
1401001--Eric-----30----100----200
1401002--Boris---70----500----300

qty column displays wrong resutl in both rows
amt2 column displays wrong resutl as 500 in both rows
only amt1 column displays correct result in both rows
SET ENGINEBEHAVIOR 70
select t1.code,t1.name,;
	sum(t2.qty) as qty,;
	sum(iif(left(t2.code,4)='3201',t2.credit,0)) as amt1,;
	sum(iif(left(t2.code,4)='3202',t2.credit,0)) as amt2 ;
	from table1 t1;
	left join table1 t2 on t1.code2 = t2.code ;
		where LEFT(t1.code,2)<>'32';
	group by t1.code;
	into cursor group_wise_sale

select group_wise_sale
brow
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform