Showing posts with label complex. Show all posts
Showing posts with label complex. Show all posts

Sunday, February 19, 2012

Help: Complex Select Statement

Here is my SQL string:

"SELECT to_ordnum, to_orddate," _
& "(SELECT SUM((DDPROD.pr_stanmat * DDPROD.pr_prfact) *
(DOBOM2.b2_quant * DDORD.or_quant)) FROM DDPROD INNER JOIN DOBOM2 ON
DDPROD.pr_prodnum = DOBOM2.b2_prodnum INNER JOIN DDORD ON
DOBOM2.b2_orid = DDORD.or_id INNER JOIN DDTORD ON DDORD.OR_TOID =
DDTORD.TO_ID WHERE DOBOM2.b2_ordnum = ''order number here from result
of outer select) AS Total" _
& "FROM DDTORD WHERE to_trak2id IN (39, 40, 41) AND to_ordtype = 's'
AND to_status = 'c' GROUP BY to_ordnum, to_orddate ORDER BY to_ordnum
DESC"

The outter Select statement returns various amounts of order numbers
represented by 'to_ordnum' in the outer Select clause which has to
meet the critera in the outer WHERE clause. I would like to place
these numbers selected into the inner WHERE clause for the inner
select statement where DOMBOM2.b2_ordnum = ?the order selected by
outer select statement.

I have tried placing to_ordnum into that location but the SQL2000
server does not process it.

Any suggestions, ideas?

Thank you,

BrettOn 5 Nov 2004 10:34:48 -0800, brett wrote:

> Here is my SQL string:
> "SELECT to_ordnum, to_orddate," _
> & "(SELECT SUM((DDPROD.pr_stanmat * DDPROD.pr_prfact) *
> (DOBOM2.b2_quant * DDORD.or_quant)) FROM DDPROD INNER JOIN DOBOM2 ON
> DDPROD.pr_prodnum = DOBOM2.b2_prodnum INNER JOIN DDORD ON
> DOBOM2.b2_orid = DDORD.or_id INNER JOIN DDTORD ON DDORD.OR_TOID =
> DDTORD.TO_ID WHERE DOBOM2.b2_ordnum = ''order number here from result
> of outer select) AS Total" _
> & "FROM DDTORD WHERE to_trak2id IN (39, 40, 41) AND to_ordtype = 's'
> AND to_status = 'c' GROUP BY to_ordnum, to_orddate ORDER BY to_ordnum
> DESC"
> The outter Select statement returns various amounts of order numbers
> represented by 'to_ordnum' in the outer Select clause which has to
> meet the critera in the outer WHERE clause. I would like to place
> these numbers selected into the inner WHERE clause for the inner
> select statement where DOMBOM2.b2_ordnum = ?the order selected by
> outer select statement.
> I have tried placing to_ordnum into that location but the SQL2000
> server does not process it.
> Any suggestions, ideas?
> Thank you,
> Brett

God, what a mess you posted. If you have a SQL question, try to get the
SQL separated from the client code that is sending it.

The confusion seems to be because you have DDTORD both in the outer select
and the inner select. You should use a table alias to differentiate them.

Here's one possibility, reformatted so it can be read:

SELECT
TBL1.to_ordnum,
TBL1.to_orddate,
( SELECT
SUM(
( DDPROD.pr_stanmat * DDPROD.pr_prfact)
* ( DOBOM2.b2_quant * DDORD.or_quant)
)
FROM DDPROD
INNER JOIN DOBOM2
ON DDPROD.pr_prodnum = DOBOM2.b2_prodnum
INNER JOIN DDORD
ON DOBOM2.b2_orid = DDORD.or_id
INNER JOIN DDTORD AS TBL2
ON DDORD.or_toid = TBL2.to_id
WHERE DOBOM2.b2_ordnum = TBL1.to_ordnum
) AS Total
FROM DDTORD AS TBL1
WHERE TBL1.to_trak2id IN (39, 40, 41)
AND TBL1.to_ordtype = 's'
AND TBL1.to_status = 'c'
GROUP BY TBL1.to_ordnum, TBL1.to_orddate
ORDER BY TBL1.to_ordnum DESC

However, without seeing DDL and sample inserts, it's impossible to test
whether this is what you meant.

Help: ADO with Unix and Oracle

We have done a complex software with VB using SQL Server through ADO. Now
our customer is planning to switch from SQL Server to Unix/Aix Oracle 8 DB.

I'm a newbie both in Oracle and Unix and wonder how this will affect our
software. Would changing the connection string be enough (I quess not).

Any help would be appreciated !

Jyrki Hamalainen
Laukaa, Finland
jyrki . hamalainen @. ids . fiOn Thu, 04 Sep 2003 08:23:14 GMT in comp.databases.ms-sqlserver,
"Jyrki H" <jyrki@.nowhere.com> wrote:

>We have done a complex software with VB using SQL Server through ADO. Now
>our customer is planning to switch from SQL Server to Unix/Aix Oracle 8 DB.
>I'm a newbie both in Oracle and Unix and wonder how this will affect our
>software.

It will probably affect your income more, think of all the dosh you
can charge for that conversion :-)

>Would changing the connection string be enough (I quess not).

I'm no oracle expert but at a guess and from experience of people in
CDMA connecting Access to Oracle the ODBC/OLEDB driver you get in
Windows won't do you any favors, IIRC Oracle has something called
SQL.NET and that's probably your best bet for the connection.

The rest will depend on how you wrote your app, if a lot of stored
procedures and triggers, etc then you're going to have fun making them
all work, I'm not sure if there's any conversion tools for converting
a database over, standard stuff should be able to be scripted (tables
and columns) but when you get to the nitty gritty, UDFs, etc. then you
may find things that are not supported or that Oracle will implement
some functionality you need in a different way.

Again I stress that I don't know Oracle and that a lot more may be
instantly convertable than I indicated... or a lot less. You have to
investigate this and come up with some time frame about how long it
will take and how much it will cost before your customer commits as
although there's a smiley on my first paragraph, it may be closer to
to the mark than you think.

Sorry I can't give you any specifics on Oracle but it's something to
start thinking about on the planning side.

I'd suggest if you haven't already done so, post a similar question in
an Oracle news group, normally when talking about conversions or
interactions between products I would recommend cross-posting to both
groups but in this case I wouldn't, IME it would likely start a flame
war, some of those Oracle guys are little, how shall I put it...
esoteric. :-)

--
A)bort, R)etry, I)nfluence with large hammer.

(replace sithlord with trevor for email)