Avatar of jaymz69
jaymz69
 asked on

How to run a few Selects

Is it possible or a better way to run this in SQL Server 2008?

This code is from my Visual Fox Pro program
but now I need to convert into SQL Server 2008 r2


SELECT ohco, ohloc, ohord_;
		FROM oohead, ooline;
		WHERE (ohco=1 AND ohloc=50 AND olico=2 AND oliloc=42);
		AND ohco=olco AND ohloc=olloc AND ohord_=olord_ and ohrel_=olrel_;
		GROUP BY ohord_ INTO CURSOR cOrders50 readwrite
		
		SELECT ohco, ohloc, ohord_;
		FROM oohead, ooline;
		WHERE (ohco=1 AND ohloc=60 AND olico=2 AND oliloc=42);
		AND ohco=olco AND ohloc=olloc AND ohord_=olord_ and ohrel_=olrel_;
		GROUP BY ohord_ INTO CURSOR cOrders60 readwrite
		
		SELECT ohco, ohloc, ohord_;
		FROM oohead, ooline;
		WHERE (ohco=2 AND ohloc=42 AND olico=1 AND oliloc=60);
		AND ohco=olco AND ohloc=olloc AND ohord_=olord_ and ohrel_=olrel_;
		GROUP BY ohord_ INTO CURSOR cOrders42 readwrite
		
*-- Union all the cursors together for one
		SELECT * FROM cOrders50 UNION SELECT * FROM cOrders60 UNION SELECT * FROM cOrders42 into cursor cAllOrders readwrite
	
*-- Count to email results		
		Count To m.COUNT

		If m.COUNT>0
-- DO Email.prg

Open in new window

Microsoft SQL Server 2008

Avatar of undefined
Last Comment
jaymz69

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Faiga Diegel

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
jaymz69

ASKER
even in an OPENQUERY?
jaymz69

ASKER
got it. Since it is OPENQUERY I changed it to do up a little.

Thank you
SELECT ohco 'Company',
	ohloc 'Location',
	ohord# 'Order'
	
	
	FROM OPENQUERY (GSFL2K, '
	SELECT *
	FROM oohead INNER JOIN ooline on ohco=olco
		AND ohloc=olloc
		AND ohord#=olord#
		AND ohrel#=olrel#
	WHERE ohco=1
		AND ohloc=50
		AND olico=2
		AND oliloc=42
UNION
	SELECT *
	FROM oohead INNER JOIN ooline on ohco=olco
		AND ohloc=olloc
		AND ohord#=olord#
		AND ohrel#=olrel#
	WHERE ohco=1
		AND ohloc=60
		AND olico=2
		AND oliloc=42
UNION
	SELECT *
	FROM oohead INNER JOIN ooline on ohco=olco
		AND ohloc=olloc
		AND ohord#=olord#
		AND ohrel#=olrel#
	WHERE ohco=2
		AND ohloc=42
		AND olico=1
		AND oliloc=60
')

Open in new window

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck