BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Paradox TQuery - select and sum....

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder Databases (Desktop)
View previous topic :: View next topic  
Author Message
MarkR
Guest





PostPosted: Thu Feb 05, 2004 12:37 am    Post subject: Paradox TQuery - select and sum.... Reply with quote



Hi guys,

I have a paradox table which I use a select statement using union on to
select two rows per table row.
example statment.

select leftcode as mycode, descript as fits, qtyinstock as stock, qtyonorder
as onorder from mytable union select rightcode as mycode, descript as fits,
qtyinstock2 as stock, qtyonorder2 as onorder from mytable

Now, I really want to return the total on order so i thought if I put
SUM(qtyinstock + qtyonorder) as STOCKAVAIL then this would be great. Alas I
get a message along the lines of you must use GROUP BY when mixing field
types.

So, how can I use GROUP BY in a statement which looks at one table twice for
each entry?

cheers


Back to top
MarkR
Guest





PostPosted: Thu Feb 05, 2004 12:49 am    Post subject: Re: Paradox TQuery - select and sum.... Reply with quote



Please ignore my post. I solved it.

select leftcode as mycode, descript as fits, sum(qtyinstock+ qtyonorder) as
totstock from mytable GROUP BY leftcode union
select leftcode as mycode, descript as fits, sum(qtyinstock2+ qtyonorder2)
as totstock from mytable GROUP BY rightcode

"MarkR" <markcr (AT) wapthespamntlworld (DOT) com> wrote

Quote:
Hi guys,

I have a paradox table which I use a select statement using union on to
select two rows per table row.
example statment.

select leftcode as mycode, descript as fits, qtyinstock as stock,
qtyonorder
as onorder from mytable union select rightcode as mycode, descript as
fits,
qtyinstock2 as stock, qtyonorder2 as onorder from mytable

Now, I really want to return the total on order so i thought if I put
SUM(qtyinstock + qtyonorder) as STOCKAVAIL then this would be great. Alas
I
get a message along the lines of you must use GROUP BY when mixing field
types.

So, how can I use GROUP BY in a statement which looks at one table twice
for
each entry?

cheers





Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder Databases (Desktop) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.