Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL Statement in Oracle & Access

Posted on 2012-03-12
5
Medium Priority
?
378 Views
Last Modified: 2012-03-27
If I have these tables

Table_A
======
Emp_Id
Emp_Name
Emp_Grade_Id

Open in new window


For example
Emp_Id        Emp_Name         Emp_Grade_Id
333              John Smith          0007
666              Mikel Josef          008

Open in new window


Table_B
======
Emp_Grade_Id
Emp_Grade_Name

Open in new window


For example
Emp_Grade_Id          Emp_Grade_Name
0007                         Manager
008                           System Analysis

Open in new window


Table_C
======
Emp_Id
ALW_DED_Id
Amount

Open in new window


For example
Emp_Id                     ALW_DED_Id            Amount
333                           1000                        500
333                           1001                        50
333                           1002                        30
333                           1003                        15

Open in new window


Table_D
======
ALW_DED_Id
ALW_DED_NAME

Open in new window


For example
ALW_DED_Id            ALW_DED_NAME
1000                        Basic
1001                        Accomadation
1002                        Electrisity
1003                        Water

Open in new window


What is the SQL Statement to display the following: -
Emp_Id     Emp_Name      Emp_Grade_Name   Basic    Accomadation    Elec   Water

Open in new window


In oracle & Access
0
Comment
Question by:egovernment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 37711253
Is there a maximum number of ALW_DED_Id entries for employees in table_C?
0
 

Author Comment

by:egovernment
ID: 37711400
Is there a maximum number of ALW_DED_Id entries for employees in table_C?
4
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 37711470
What version of Access are you using?

Try this for Oracle:

select a.emp_id, a.emp_name,
	b.emp_grade_name,
	max(case when c.alw_ded_id = '1000' then alw_ded_name end) basic,
	max(case when c.alw_ded_id = '1001' then alw_ded_name end) accomadation,
	max(case when c.alw_ded_id = '1002' then alw_ded_name end) electricity,
	max(case when c.alw_ded_id = '1001' then alw_ded_name end) water
from table_a a,
	table_b b,
	table_c c,
	table_d d
where a.emp_grade_id=b.emp_grade_id and 
	a.emp_id=c.emp_id and
	c.alw_ded_id=d.alw_ded_id
group by a.emp_id, a.emp_name, b.emp_grade_name
/

Open in new window

0
 

Author Comment

by:egovernment
ID: 37712812
What version of Access are you using?
Access 2003
0
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 2000 total points
ID: 37714372
First there is a typo in the SQL I posted above.

Change:        max(case when c.alw_ded_id = '1001' then alw_ded_name end) water
To:       max(case when c.alw_ded_id = '1003' then alw_ded_name end) water


Access doesn't appear to have a CASE statement in SQL but they have a SWITCH function that bascially does the same thing.

I don't have Access 2003 around but the following was tested in Access 2007 and should run fine in 2003.

SELECT table_a.Emp_Id, table_a.Emp_Name, table_b.Emp_Grade_Name, 
   max(Switch(  table_c.ALW_DED_Id="1000",alw_ded_name )) AS Basic,
   max(Switch(  table_c.ALW_DED_Id="1001",alw_ded_name )) AS Accomadation,
   max(Switch(  table_c.ALW_DED_Id="1002",alw_ded_name )) AS Electricity,
   max(Switch(  table_c.ALW_DED_Id="1003",alw_ded_name )) AS Water
FROM table_d INNER JOIN (table_c INNER JOIN (table_a INNER JOIN table_b ON table_a.Emp_Grade_Id = table_b.Emp_Grade_Id) ON table_c.Emp_Id = table_a.Emp_Id) ON table_d.ALW_DED_Id = table_c.ALW_DED_Id
group by  table_a.Emp_Id, table_a.Emp_Name, table_b.Emp_Grade_Name;

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Suggested Courses

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question