473,406 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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 5345
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.