472,373 Members | 1,915 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,373 software developers and data experts.

Converting positive number to negative number

Hi all,

I have two querys

QueryPurchased
ProductID Location TotPcs
Prod1 Loc1 100
Prod2 Loc1 50
Prod3 Loc1 150
Prod3 Loc3 150

QuerySold
ProductID Location TotPcs
Prod1 Loc1 20
Prod2 Loc1 10
Prod3 Loc1 50
Prod3 Loc2 125
I want the result query to show as follows

QueryBalance
ProductID Location TotPcs
Prod1 Loc1 80
Prod2 Loc1 40
Prod3 Loc1 100
Prod3 Loc2 25

I can use a UNION ALL command to bring together
QueryPurchased query and QuerySold query but that will
just add the TotPcs instead of subtracting it.

I have a thought but don't know how to implement it.

If I can convert the TotPcs numbers of QuerySold query
from positive to negative and then do a UNION ALL then
I can achieve what I want to do or so I think.

Any suggestion or alternates will highly be
appreciated.

Thanking you all in advance

Nov 13 '05 #1
7 5208
From: "" <os******@eircom.net>
Newsgroups: comp.databases.ms-access
Subject: Re: Converting positive number to negative number
Date: Wed, 14 Sep 2005 07:41:34 -0700
ha*******@yahoo.com wrote:
Hi all,

I have two querys

QueryPurchased
ProductID Location TotPcs
Prod1 Loc1 100
Prod2 Loc1 50
Prod3 Loc1 150
Prod3 Loc3 150

QuerySold
ProductID Location TotPcs
Prod1 Loc1 20
Prod2 Loc1 10
Prod3 Loc1 50
Prod3 Loc2 125
I want the result query to show as follows

QueryBalance
ProductID Location TotPcs
Prod1 Loc1 80
Prod2 Loc1 40
Prod3 Loc1 100
Prod3 Loc2 25

I can use a UNION ALL command to bring together
QueryPurchased query and QuerySold query but that will
just add the TotPcs instead of subtracting it.

I have a thought but don't know how to implement it.

If I can convert the TotPcs numbers of QuerySold query
from positive to negative and then do a UNION ALL then
I can achieve what I want to do or so I think.

Any suggestion or alternates will highly be
appreciated.

Thanking you all in advance

Put a minus in front of the value you want to negate in the Union
Query...

e.g.

SELECT t1.ProductID, t1.Location, t1.TotPCs
FROM t1
UNION ALL SELECT t2.ProductID, t2.Location, -(t2.TotPCs)
FROM t2;
Then create a new select query from this union query. Sum the TotPcs
Field.

osmethod

Nov 13 '05 #2
ha*******@yahoo.com wrote:
Hi all,

I have two querys

QueryPurchased
ProductID Location TotPcs
Prod1 Loc1 100
Prod2 Loc1 50
Prod3 Loc1 150
Prod3 Loc3 150

QuerySold
ProductID Location TotPcs
Prod1 Loc1 20
Prod2 Loc1 10
Prod3 Loc1 50
Prod3 Loc2 125
I want the result query to show as follows

QueryBalance
ProductID Location TotPcs
Prod1 Loc1 80
Prod2 Loc1 40
Prod3 Loc1 100
Prod3 Loc2 25

I can use a UNION ALL command to bring together
QueryPurchased query and QuerySold query but that will
just add the TotPcs instead of subtracting it.

I have a thought but don't know how to implement it.

If I can convert the TotPcs numbers of QuerySold query
from positive to negative and then do a UNION ALL then
I can achieve what I want to do or so I think.

Any suggestion or alternates will highly be
appreciated.

Thanking you all in advance


At first I thought there was a 1 to 1 relationship...for every Purchase
there'd be a sold. Your example is a bit confusing since you have a
Purchase for Loc3 but you subtract it from Loc2 in Sold.

If there is a 1 to 1 purchase to sold, link the product/loc in the query
and you have the results to calc.

If there is all purchase but some missing solds...or visa versa, you can
create the query to select all records in purchase and only those that
match in sole....or all records in sold and only those matching in purchase.

You could create a union query to select all products/locs from
purchase/sold and make each product/loc distinct or else use a totals
query. Then use this query as the main table and add purchases and sold
tables/queries and select all records from the union of product/log and
only those that match for purchases and only those that match from sold.
To do so, double click on the relationship line and set accordingly.
Nov 13 '05 #3

ha*******@yahoo.com wrote:
Hi all,

I have two querys

QueryPurchased
ProductID Location TotPcs
Prod1 Loc1 100
Prod2 Loc1 50
Prod3 Loc1 150
Prod3 Loc3 150

QuerySold
ProductID Location TotPcs
Prod1 Loc1 20
Prod2 Loc1 10
Prod3 Loc1 50
Prod3 Loc2 125
I want the result query to show as follows

QueryBalance
ProductID Location TotPcs
Prod1 Loc1 80
Prod2 Loc1 40
Prod3 Loc1 100
Prod3 Loc2 25

I can use a UNION ALL command to bring together
QueryPurchased query and QuerySold query but that will
just add the TotPcs instead of subtracting it.

I have a thought but don't know how to implement it.

If I can convert the TotPcs numbers of QuerySold query
from positive to negative and then do a UNION ALL then
I can achieve what I want to do or so I think.

Any suggestion or alternates will highly be
appreciated.

Thanking you all in advance

Put a minus in front of the value you want to negate in the Union
Query...

e.g.

SELECT t1.ProductID, t1.Location, t1.TotPCs
FROM t1
UNION ALL SELECT t2.ProductID, t2.Location, -(t2.TotPCs)
FROM t2;
Then create a new select query from this union query. Sum the TotPcs
Field.

osmethod

Nov 13 '05 #4

ha*******@yahoo.com wrote:
Hi all,

I have two querys

QueryPurchased
ProductID Location TotPcs
Prod1 Loc1 100
Prod2 Loc1 50
Prod3 Loc1 150
Prod3 Loc3 150

QuerySold
ProductID Location TotPcs
Prod1 Loc1 20
Prod2 Loc1 10
Prod3 Loc1 50
Prod3 Loc2 125
I want the result query to show as follows

QueryBalance
ProductID Location TotPcs
Prod1 Loc1 80
Prod2 Loc1 40
Prod3 Loc1 100
Prod3 Loc2 25

I can use a UNION ALL command to bring together
QueryPurchased query and QuerySold query but that will
just add the TotPcs instead of subtracting it.

I have a thought but don't know how to implement it.

If I can convert the TotPcs numbers of QuerySold query
from positive to negative and then do a UNION ALL then
I can achieve what I want to do or so I think.

Any suggestion or alternates will highly be
appreciated.

Thanking you all in advance

Put a minus in front of the value you want to negate in the Union
Query...

e.g.

SELECT t1.ProductID, t1.Location, t1.TotPCs
FROM t1
UNION ALL SELECT t2.ProductID, t2.Location, -(t2.TotPCs)
FROM t2;
Then create a new select query from this union query. Sum the TotPcs
Field.

osmethod

Nov 13 '05 #5
Salad, sorry for confusion typo error on my part. I sincerely
apologise.
The last line on all three queries should read as follows.

ProductID Location
Prod3 Loc2

Nov 13 '05 #6
ha*******@yahoo.com wrote:
Salad, sorry for confusion typo error on my part. I sincerely
apologise.
The last line on all three queries should read as follows.

ProductID Location
Prod3 Loc2

DId you follow what I wrote?
Nov 13 '05 #7
Thanks for your suggestion osmet, it worked well and got the results as
I wanted

Nov 13 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: pj | last post by:
Why does M$ Query Analyzer display all numbers as positive, no matter whether they are truly positive or negative ? I am having to cast each column to varchar to find out if there are any...
2
by: bafidi | last post by:
i write a number to textbox1.text i want to learn if it is negative or positive
19
by: Harshan | last post by:
The range of signed int is - 2^15 to + (2^15 )-1 (-32768 to 32767) Why the one less at positive Range ? (compared to the negative side..!) I came to know that it uses 2's compliment...
3
by: Ken Durden | last post by:
Is it possible to force positive values to have the + sign prefixed on them? double f1 = 1024.2; double f2 = -1024.2; string.Format( "{0:F}", f1 ); // +1024.2 string.Format( "{0:F}", f2 );...
10
by: JT | last post by:
Need some help in converting a byte to a signed int. This is what I have attempted to do: byte bytes = new byte { 0xFF, 0xFF, 0x9C}; StringBuilder hexString = new StringBuilder(); foreach...
15
by: jaks.maths | last post by:
How to convert negative integer to hexadecimal or octal number? Ex: -568 What is the equivalent hexadecimal and octal number??
19
by: Johs | last post by:
I need to make some special action if 'a' and 'b' are both positive or both negative. Is there some inbuilt function to check this? Johs
63
by: deepak | last post by:
Hi, Can someone give the standard function which can create positive integer value in C? Thanks, Deepak
0
lee123
by: lee123 | last post by:
i am making a program that is about algebra and i want to know how can i get it to put negative and positive numbers in a text box for example if i had a problem that is: -6(2x + 10) = -48, ...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.