473,396 Members | 2,113 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,396 software developers and data experts.

Query with multiple outputs

Can anyone tell me how to write a query that does the following:

1. source file: Account Number numeric
Select 1 numeric
Select 2 numeric

2. output file: Account number
select if present.

The result output could have no output account if neither select has a value
or
the result output could have a single output record for the account if only
1 select value
or
the result output could have two output records one for account and select 1
and one for account and select 2.

So one input record could create 0, 1, or 2 output records.

Any help will be appreicated.

Jim Reid
Ja*******@Verizon.net
Nov 13 '05 #1
4 1770
What, exactly do you mean by "select 1 numeric", "select 2 numeric", and
"select if present" -- is each of these supposed to represent a field name,
or does each represent a "select" action? I am having some difficulty
understanding your question. If we can understand what you have and what you
are asking, perhaps someone can offer a worthwhile suggestion.

"JAMES L REID" <ja*******@verizon.net> wrote in message
news:R07ud.1812$sU4.1405@trndny01...
Can anyone tell me how to write a query that does the following:

1. source file: Account Number numeric
Select 1 numeric
Select 2 numeric

2. output file: Account number
select if present.

The result output could have no output account if neither select has a value or
the result output could have a single output record for the account if only 1 select value
or
the result output could have two output records one for account and select 1 and one for account and select 2.

So one input record could create 0, 1, or 2 output records.

Any help will be appreicated.

Jim Reid
Ja*******@Verizon.net

Nov 13 '05 #2
JAMES L REID wrote:
Can anyone tell me how to write a query that does the following:


If I understand what you're saying:

tblAccountOptions
Account Number Double (Primary Key?)
Select 1 Double
Select 2 Double
1234.2 Null Null
1234.3 83.1 54.2
1234.4 Null 51.0

should give:

1234.3 83.1
1234.3 54.2
1234.4 51.0

SELECT A.[Account Number], A.[Select 1] AS Selected
FROM tblAccountOptions AS A INNER JOIN tblAccountOptions ON A.[Account
Number] = tblAccountOptions.[Account Number]
WHERE (((A.[Select 1]) Is Not Null)) UNION SELECT A.[Account Number],
A.[Select 2] AS Selected
FROM tblAccountOptions AS A INNER JOIN tblAccountOptions ON A.[Account
Number] = tblAccountOptions.[Account Number]
WHERE (((A.[Select 2]) Is Not Null));

gave me:

Account Number Selected
1234.3 54.2
1234.3 83.1
1234.4 51

Note that the word 'select' by itself is a reserved word. Yes, I tried
using it first. Duh! :-)

James A. Fortune

Nov 13 '05 #3
Well folks I found out how to do what I wanted. I don't think I explained
it well so here goes again.

Select a, b, iff(b>0,Null,Null) as c from file1
Union Select a,iff(c>0,null,null) as b,c from file1;

what this gives me is the following:

File1:
a b c
1 2 3
2 4 5
3 6

Output:
a b c
1 2
1 3
2 4
2 5
3 6

For every input record I'm getting at least 1 maybe 2 output records
depending on what is in B & C. Hopefully this will help others trying to do
the same thing in the future.

Thanks for your help folks.

Jim

<ji********@compumarc.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
JAMES L REID wrote:
Can anyone tell me how to write a query that does the following:


If I understand what you're saying:

tblAccountOptions
Account Number Double (Primary Key?)
Select 1 Double
Select 2 Double
1234.2 Null Null
1234.3 83.1 54.2
1234.4 Null 51.0

should give:

1234.3 83.1
1234.3 54.2
1234.4 51.0

SELECT A.[Account Number], A.[Select 1] AS Selected
FROM tblAccountOptions AS A INNER JOIN tblAccountOptions ON A.[Account
Number] = tblAccountOptions.[Account Number]
WHERE (((A.[Select 1]) Is Not Null)) UNION SELECT A.[Account Number],
A.[Select 2] AS Selected
FROM tblAccountOptions AS A INNER JOIN tblAccountOptions ON A.[Account
Number] = tblAccountOptions.[Account Number]
WHERE (((A.[Select 2]) Is Not Null));

gave me:

Account Number Selected
1234.3 54.2
1234.3 83.1
1234.4 51

Note that the word 'select' by itself is a reserved word. Yes, I tried
using it first. Duh! :-)

James A. Fortune

Nov 13 '05 #4
Well folks I found out how to do what I wanted. I don't think I explained
it well so here goes again.

Select a, b, iff(b>0,Null,Null) as c from file1
Union Select a,iff(c>0,null,null) as b,c from file1;

what this gives me is the following:

File1:
a b c
1 2 3
2 4 5
3 6

Output:
a b c
1 2
1 3
2 4
2 5
3 6

For every input record I'm getting at least 1 maybe 2 output records
depending on what is in B & C. Hopefully this will help others trying to do
the same thing in the future.

Thanks for your help folks.

Jim

<ji********@compumarc.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
JAMES L REID wrote:
Can anyone tell me how to write a query that does the following:


If I understand what you're saying:

tblAccountOptions
Account Number Double (Primary Key?)
Select 1 Double
Select 2 Double
1234.2 Null Null
1234.3 83.1 54.2
1234.4 Null 51.0

should give:

1234.3 83.1
1234.3 54.2
1234.4 51.0

SELECT A.[Account Number], A.[Select 1] AS Selected
FROM tblAccountOptions AS A INNER JOIN tblAccountOptions ON A.[Account
Number] = tblAccountOptions.[Account Number]
WHERE (((A.[Select 1]) Is Not Null)) UNION SELECT A.[Account Number],
A.[Select 2] AS Selected
FROM tblAccountOptions AS A INNER JOIN tblAccountOptions ON A.[Account
Number] = tblAccountOptions.[Account Number]
WHERE (((A.[Select 2]) Is Not Null));

gave me:

Account Number Selected
1234.3 54.2
1234.3 83.1
1234.4 51

Note that the word 'select' by itself is a reserved word. Yes, I tried
using it first. Duh! :-)

James A. Fortune

Nov 13 '05 #5

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

Similar topics

66
by: Darren Dale | last post by:
Hello, def test(data): i = ? This is the line I have trouble with if i==1: return data else: return data a,b,c,d = test()
9
by: Mark | last post by:
I've run a few simple tests looking at how query string encoding/decoding gets handled in asp.net, and it seems like the situation is even messier than it was in asp... Can't say I think much of the...
3
by: Bill Nguyen | last post by:
I'm working on a project that requires outputs to be sent to multiple windows on a single monitor. I have no idea whether .NET can provide this capability. Also, is there any utility/control out...
0
by: Jim Kennedy | last post by:
If you are firing that many queries you better be using bind variables and parsing the query once and rebinding, and executing many times and NOT closing the cursor. Doing that will help you...
3
by: rinu911 | last post by:
hi all I am tring to insert a values to a table by checking if the value is there in the table already but it gives me this error "Query input must contain at least one table or query" ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.