473,472 Members | 2,181 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Returning one field multiple times with different values

5 New Member
Table 1 has Merchandise Class and 4 GL account number fields.
Expand|Select|Wrap|Line Numbers
  1. Merch     InventoryAcct      CostAcct      PayableAcct   SalesAcct
  2. Fish          1000             5000             2000          4000
  3. Beef          1100             5100             2100          4100
Table 2 is the GL Master table which hold Account #s and Account Descriptions
Expand|Select|Wrap|Line Numbers
  1. Acct      Description
  2. 1000       Fish Inventory
  3. 1100       Beef Inventory
  4. etc.
I want to return:
Expand|Select|Wrap|Line Numbers
  1. Merch   InvAcct   InvAcctDesc         CostAcct    CostAcctDesc    etc....
  2. Fish      1000      Fish Inventory      5000           Fish Cost
  3. Beef      1100      Beef Inventory      5100           Beef Cost
  4. etc..
I am querying an Informix database (unsure of version) on a Linux (Redhat) server using a variety of tools, including Crystal Reports and MS Query (through and ODBC link) and 'dbaccess', a program on the Linux server.

Also, as a bonus question, what book(s) or websites would you recommend to me to teach myself SQL?
Apr 3 '08 #1
7 1788
ck9663
2,878 Recognized Expert Specialist
Table 1 has Merchandise Class and 4 GL account number fields.
Expand|Select|Wrap|Line Numbers
  1. Merch     InventoryAcct      CostAcct      PayableAcct   SalesAcct
  2. Fish          1000             5000             2000          4000
  3. Beef          1100             5100             2100          4100
Table 2 is the GL Master table which hold Account #s and Account Descriptions
Expand|Select|Wrap|Line Numbers
  1. Acct      Description
  2. 1000       Fish Inventory
  3. 1100       Beef Inventory
  4. etc.
I want to return:
Expand|Select|Wrap|Line Numbers
  1. Merch   InvAcct   InvAcctDesc         CostAcct    CostAcctDesc    etc....
  2. Fish      1000      Fish Inventory      5000           Fish Cost
  3. Beef      1100      Beef Inventory      5100           Beef Cost
  4. etc..
I am querying an Informix database (unsure of version) on a Linux (Redhat) server using a variety of tools, including Crystal Reports and MS Query (through and ODBC link) and 'dbaccess', a program on the Linux server.

Also, as a bonus question, what book(s) or websites would you recommend to me to teach myself SQL?
Try:

select Merch, InventoryAcct , CostAcct, PayableAcct, SalesAcct
from MerchandiseClass
inner join GLMaste ron MerchandiseClass.InventoryAcct = GLMaster.Acct

You did not include the table for CostAcctDesc so I would'nt know where to get it.

Also, INNER join was used assuming all InventoryAcct are in Acct

-- CK
Apr 3 '08 #2
Marcotte
5 New Member
Try:

select Merch, InventoryAcct , CostAcct, PayableAcct, SalesAcct
from MerchandiseClass
inner join GLMaste ron MerchandiseClass.InventoryAcct = GLMaster.Acct

You did not include the table for CostAcctDesc so I would'nt know where to get it.

Also, INNER join was used assuming all InventoryAcct are in Acct

-- CK
CostAcctDesc is on the GLMaster table.
Don't I also need to select AcctDesc?

I get a syntax error when I try your query (see below). Oddly, it appears that the error is "join". After I get the syntax error message, when I go back into the editor the cursor goes to the "join" on line three.

select m_mcl, m_cst, m_sal, m_cic, m_ipa
from mglasg
inner join glgmas on mglasg.m_cst = glgmas.glmacn

table mglasg (Merchandise Class Master) contains:
m_mcl = Merch Class Code
m_cst = Inventory Acct
m_sal = Sales Acct
m_cic = Cost Acct
m_ipa = Payable Acct

glgmas is the GL Master table which is a list of GL accounts (glmacn) and their corresponding descriptions (glmdes).

Here is what I originally tried:
select m_mcl, m_cst, m_sal, m_cic, m_ipa, glmdes
from mglasg, glgmas
where m_cst = glmacn

but this returns:
Expand|Select|Wrap|Line Numbers
  1. Merch   InvAcct   InvAcctDesc         CostAcct    CostAcctDesc    etc....
  2. Fish      1000      Fish Inventory      5000           Fish Inventory
  3. Beef      1100      Beef Inventory      5100           Beef Inventory
  4. etc..
In other words, it's matching the inventory account (oddly named m_cst) to the glgmas.glmacn field and returning glmdes which is Fish (or Beef, etc.) Inventory, whereas I want column 3 of my returned data to be the Inventory Account Description and column 5 to be the Cost Account Description (there would also be columns 6-9 for Sales and Payable account # and description).
Apr 3 '08 #3
ck9663
2,878 Recognized Expert Specialist
CostAcctDesc is on the GLMaster table.
Don't I also need to select AcctDesc?

I get a syntax error when I try your query (see below). Oddly, it appears that the error is "join". After I get the syntax error message, when I go back into the editor the cursor goes to the "join" on line three.

select m_mcl, m_cst, m_sal, m_cic, m_ipa
from mglasg
inner join glgmas on mglasg.m_cst = glgmas.glmacn

table mglasg (Merchandise Class Master) contains:
m_mcl = Merch Class Code
m_cst = Inventory Acct
m_sal = Sales Acct
m_cic = Cost Acct
m_ipa = Payable Acct

glgmas is the GL Master table which is a list of GL accounts (glmacn) and their corresponding descriptions (glmdes).

Here is what I originally tried:
select m_mcl, m_cst, m_sal, m_cic, m_ipa, glmdes
from mglasg, glgmas
where m_cst = glmacn

but this returns:
Expand|Select|Wrap|Line Numbers
  1. Merch   InvAcct   InvAcctDesc         CostAcct    CostAcctDesc    etc....
  2. Fish      1000      Fish Inventory      5000           Fish Inventory
  3. Beef      1100      Beef Inventory      5100           Beef Inventory
  4. etc..
In other words, it's matching the inventory account (oddly named m_cst) to the glgmas.glmacn field and returning glmdes which is Fish (or Beef, etc.) Inventory, whereas I want column 3 of my returned data to be the Inventory Account Description and column 5 to be the Cost Account Description (there would also be columns 6-9 for Sales and Payable account # and description).
Sorry, my bad. the GLMaster and on got stuck together.

Try this:
Expand|Select|Wrap|Line Numbers
  1. select Merch, InventoryAcct , CostAcct, PayableAcct, SalesAcct, inventory.Description as InvAcctDesc, Cost.Description as CostAcctDesc              
  2. from MerchandiseClass
  3. inner join GLMaster inventory on MerchandiseClass.InventoryAcct = inventory.Acct
  4. inner join GLMaster Cost on MerchandiseClass.CostAcct = Cost.Acct
-- CK
Apr 3 '08 #4
Marcotte
5 New Member
Sorry, my bad. the GLMaster and on got stuck together.

Try this:
Expand|Select|Wrap|Line Numbers
  1. select Merch, InventoryAcct , CostAcct, PayableAcct, SalesAcct, inventory.Description as InvAcctDesc, Cost.Description as CostAcctDesc              
  2. from MerchandiseClass
  3. inner join GLMaster inventory on MerchandiseClass.InventoryAcct = inventory.Acct
  4. inner join GLMaster Cost on MerchandiseClass.CostAcct = Cost.Acct
-- CK
No, the syntax error wasn't due to the "GLMaste ron" part of your first post. I translated it all into the field names. The query that generated the error is that one in my first reply (2nd post), and it appears not to like the join keyword for some strange reason.

I have a call into our software vendor. Perhaps it has something to do with this particular flavor of Informix. When I've needed to to inner joins before I've just used a WHERE clause.

In the query you just posted, what exactly do you mean by "inventory.description as InvAcctDesc"? Which of those are table names, field names and aliases?
Apr 3 '08 #5
ck9663
2,878 Recognized Expert Specialist
No, the syntax error wasn't due to the "GLMaste ron" part of your first post. I translated it all into the field names. The query that generated the error is that one in my first reply (2nd post), and it appears not to like the join keyword for some strange reason.

I have a call into our software vendor. Perhaps it has something to do with this particular flavor of Informix. When I've needed to to inner joins before I've just used a WHERE clause.

In the query you just posted, what exactly do you mean by "inventory.description as InvAcctDesc"? Which of those are table names, field names and aliases?

Whenever you see this ""inventory.description as InvAcctDesc", it means inventory.description is a column on the table and InvAcctDesc will be the new name/alias. If you save the query into a new table using the INTO keyword, the new name/alias will be the column name of the new table. So it has to be unique.

-- CK
Apr 4 '08 #6
Marcotte
5 New Member
I finally got it to work with this:
Expand|Select|Wrap|Line Numbers
  1. select m_mcl , m_dsc, m_sal ,
  2. (select glmdsc Desc from glgmas where
  3. m_sal=glmacn),
  4.  
  5. m_cst,
  6. (select glmdsc from glgmas where
  7. m_cst=glmacn),
  8.  
  9. m_cic,
  10. (select glmdsc from glgmas where
  11. m_cic=glmacn),
  12.  
  13. m_ipa,
  14. (select glmdsc from glgmas where
  15. m_ipa=glmacn)
  16.  
  17. from mglasg
  18.  
Apr 10 '08 #7
ck9663
2,878 Recognized Expert Specialist
That'll be slow specially if you have big tables. But if it suit you and it's working, it's your call.

-- CK
Apr 10 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Burton Figg | last post by:
I have a SELECT statement which holds a list of times (for adding appointments to a database): e.g. <select name="time" id="time" size="3" multiple> <option value="00:00">00:00</option>...
6
by: Samuel Hon | last post by:
Hi I'm not sure what the best approach for this is: I have a stored procedure which I would like to use to return several output values instead of returning a recordset. CREATE PROCEDURE...
17
by: Roland Hall | last post by:
Is there a way to return multiple values from a function without using an array? Would a dictionary object work better? -- Roland Hall /* This information is distributed in the hope that it...
1
by: Ben | last post by:
I have a Tabular form bound to a table. The purpose of this form is to get times from a timer and record them in a field. The timer dumps the time automatically through a serial port. When the time...
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
9
by: Karl O. Pinc | last post by:
I want to return multiple values, but not a set, only a single row, from a plpgsql function and I can't seem to get it to work. (I suppose I'd be happy to return a set, but I can't seem to make...
5
by: littlevikinggirl | last post by:
Hi, I posted a badly worded question last week so got no replies and am still struggling to figure out the problem myself. I have a table containing two fields, Location and Serial Number. I...
0
chumlyumly
by: chumlyumly | last post by:
Hello scripters - OS: Mac OSX Language: PHP w/ MySQL database I've created an insert page where a user inputs his info, which then goes to four different tables in a MySQL database. The...
3
by: klbachrodt | last post by:
Hi all - I've been browsing this forum for a while now, looking for help, and finally decided to join and ask my question, since I'm not terribly good at writing SQL queries in Access. Here is my...
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
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...
1
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...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.