Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Procedural vs Select-SQL code
Message
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01167729
Message ID:
01167732
Views:
8
Here is the code for the problem:
LOCAL lSelectWay
lSelectWay = .F. && Set to true if you prefer select solution

IF m.lSelectWay
	LOCAL lcWhere, lcOldANSI
	lcOldANSI = SET("Ansi")
	SET ANSI OFF

	lcWhere = [Styles.cStyle NOT IN ("F","S","X","D","M", "CD", "PK") ] + ;
		[and NOT Styles.cStyle LIKE "%.%"] && [Styles.In_Stock <=1 ]

	DO CASE
	CASE m.cact = "A" && Active
		lcWhere = m.lcWhere + [ and Styles.DisContinu = "A"]

	CASE m.cact = "I" && Inactive
		lcWhere = m.lcWhere + [ and Styles.DisContinu = "I"]

	CASE m.cact = "B" && Both 
		lcWhere = m.lcWhere + [ and Styles.DisContinu IN ("A","I")]
	ENDCASE

	USE styles INDEX styles IN 0 && Style
	USE or_items INDEX or_style, or_items IN 0 && Style, PON + Style
	USE orders INDEX orders IN 0 && PON

	LOCAL loThermo, lcClass
	lcClass = "cusSQLThermo"
	loThermo = CREATEOBJECT(m.lcClass) && we need visual indication for long select

	SELECT styles.cStyle, styles.RESERVED AS nReserved, styles.in_stock AS nInStock, ;
		SUM(IIF(orders.acc = "HOUSE" AND (NOT approved == "" OR NOT app_date = {}), ;
		or_items.qty-or_items.shiped-or_items.can_qty, 000000000.00)) AS nHouseOrder ;
		FROM styles INNER JOIN or_items ON styles.cStyle = or_items.cStyle ;
		INNER JOIN orders ON or_items.pon + or_items.cStyle = orders.pon ;
		WHERE &lcWhere ;
		GROUP BY 1,2,3 HAVING nReserved - (nHouseOrder + nInStock)<= 0 ;
		INTO CURSOR dummy READWRITE
	RELEASE loThermo
	SELECT dummy

	SET ANSI &lcOldANSI && Restore ANSI settings

	IF RECCOUNT('Dummy') = 0
		DO give_mes WITH 'No Records'
		RETURN
	ENDIF
ELSE
	USE styles
	USE or_items INDEX or_style IN 0
	USE orders INDEX orders IN 0

	SELECT styles
	SET FILTER TO !'.'$cStyle .AND. !LEFT(cStyle,1)$'FSXDM' .AND.;
		!LEFT(cStyle,2)$'CD PK'
	COPY TO dummy FIELDS cStyle, RESERVED, in_Stock ;
	FOR (cact='A' AND discontinu="A") OR ;
		(cact='I' AND discontinu='I') OR (cact='B' AND discontinu$'AI')
	SET INDEX TO styles
	USE dummy EXCLUSIVE IN 0
	SELECT dummy
	INDEX ON cStyle TO dummy
	SCAN
		WAIT cStyle NOWAIT WINDOW
		SELE or_items
		SEEK dummy.cStyle
		lnOnOrderQty=0
		SCAN WHILE cStyle=dummy.cStyle
			SELE orders
			SEEK or_items.pon
			IF acc='HOUSE' .AND. (!EMPTY(approved) .OR. !EMPTY(app_date))
				SELECT or_items
				lnOnOrderQty=lnOnOrderQty+(qty-shiped-can_qty)
				IF lnOnOrderQty>(dummy.RESERVED - dummy.in_stock) && We don't need to see these items
					SELECT dummy
					DELETE NEXT 1
					LOOP
				ENDIF
			ENDIF
		ENDSCAN
	ENDSCAN
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform