473,508 Members | 2,119 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Self Joins

Hi, I want to display the results of the following query in my
program.
select a.cdecode as cdecode, a.cdename as cdename, a.cdecallid as
cdecallid, a.cderecID as cderecid, b.cdecode as bcdecode, b.cdename as
bcdename, b.cdecallid as bcdecallid, b.cderecid as bcderecid
from shrcodemaster a
right outer join shrcodemaster b
on a.cdeRecID = b.cdeRecid
and a.cdecallid = 'B'
The query is giving me the following results

cdecode cdename cdecallid cderecid bcdecode bcdename bdecallid
bcderecid
MYR Malaysian ringgit B 2 MYR Malaysian ringgit B
2
NULL NULL NULL NULL AUD Australian dollar S 3
USD US dollar B 4 USD US dollar B 4
CNY Chinese yuan B 5 CNY Chinese yuan B
5
NULL NULL NULL NULL JPY Japanese yen (1) S 6
IDR Indonesian Rupiah B 7 IDR Indonesian Rupiah B 7
TWD New Taiwan dollar B 8 TWD New Taiwan dollar B 8
HKD Hong Kong dollar B 9 HKD Hong Kong dollar B 9
NULL NULL NULL NULL sgl Singapore S 10
NULL NULL NULL NULL MY Malaysia S 11
CN China B 12 CN China B 12

How can I change my query so that for a cderecid, if cdecallid is 'B'
then it should return NULL values for bcdecode, bcdename, bcdecallid,
bcderecid.

Just like for a bcdrecid, if bcdecallid is S, it is returning NULL
values for cdecode,cdename,cdecallid, cderecid.

Pls assist me. Its quite urgent.

I want out put similar to

cdecode cdename cdecallid cderecid bcdecode bcdename bdecallid
bcderecid
MYR Malaysian ringgit B 2 NULL NULL NULL
NULL
NULL NULL NULL NULL AUD Australian dollar S 3
USD US dollar B 4 NULL NULL NULL
NULL
CNY Chinese yuan B 5 NULL NULL NULL
NULL
NULL NULL NULL NULL JPY Japanese yen (1) S 6
IDR Indonesian Rupiah B 7 NULL NULL NULL
NULL
TWD New Taiwan dollar B 8 NULL NULL NULL
NULL
HKD Hong Kong dollar B 9 NULL NULL NULL
NULL
NULL NULL NULL NULL sgl Singapore S 10
NULL NULL NULL NULL MY Malaysia S 11
CN China B 12 NULL NULL NULL NULL

Regards,
Omavlana
Jul 20 '05 #1
1 1846
Oh man! It took me more than half an hour to parse your script and its
output. Please write your codes more readable so people don't give up
understanding your problem :-)
Anyway, your desired result set didn't make sense to me, but I just assume
what you have written is really what you need. So this is probably the query
you want:

select a.cdecode,
a.cdename,
a.cdecallid,
a.cderecID,
case when a.cdecallid = 'B' then NULL else b.cdecode end as
bcdecode,
case when a.cdecallid = 'B' then NULL else b.cdename end as
bcdename,
case when a.cdecallid = 'B' then NULL else b.cdecallid end as
bcdecallid,
case when a.cdecallid = 'B' then NULL else b.cderecid end as
bcderecid
from shrcodemaster a right outer join shrcodemaster b on a.cdeRecID =
b.cdeRecid and a.cdecallid = 'B'

I hope it work...

Good luck,
Shervin
"Omavlana" <ki***@boardroomlimited.com> wrote in message
news:b1**************************@posting.google.c om...
Hi, I want to display the results of the following query in my
program.
select a.cdecode as cdecode, a.cdename as cdename, a.cdecallid as
cdecallid, a.cderecID as cderecid, b.cdecode as bcdecode, b.cdename as
bcdename, b.cdecallid as bcdecallid, b.cderecid as bcderecid
from shrcodemaster a
right outer join shrcodemaster b
on a.cdeRecID = b.cdeRecid
and a.cdecallid = 'B'
The query is giving me the following results

cdecode cdename cdecallid cderecid bcdecode bcdename bdecallid
bcderecid
MYR Malaysian ringgit B 2 MYR Malaysian ringgit B
2
NULL NULL NULL NULL AUD Australian dollar S 3
USD US dollar B 4 USD US dollar B 4
CNY Chinese yuan B 5 CNY Chinese yuan B
5
NULL NULL NULL NULL JPY Japanese yen (1) S 6
IDR Indonesian Rupiah B 7 IDR Indonesian Rupiah B 7
TWD New Taiwan dollar B 8 TWD New Taiwan dollar B 8
HKD Hong Kong dollar B 9 HKD Hong Kong dollar B 9
NULL NULL NULL NULL sgl Singapore S 10
NULL NULL NULL NULL MY Malaysia S 11
CN China B 12 CN China B 12

How can I change my query so that for a cderecid, if cdecallid is 'B'
then it should return NULL values for bcdecode, bcdename, bcdecallid,
bcderecid.

Just like for a bcdrecid, if bcdecallid is S, it is returning NULL
values for cdecode,cdename,cdecallid, cderecid.

Pls assist me. Its quite urgent.

I want out put similar to

cdecode cdename cdecallid cderecid bcdecode bcdename bdecallid
bcderecid
MYR Malaysian ringgit B 2 NULL NULL NULL
NULL
NULL NULL NULL NULL AUD Australian dollar S 3
USD US dollar B 4 NULL NULL NULL
NULL
CNY Chinese yuan B 5 NULL NULL NULL
NULL
NULL NULL NULL NULL JPY Japanese yen (1) S 6
IDR Indonesian Rupiah B 7 NULL NULL NULL
NULL
TWD New Taiwan dollar B 8 NULL NULL NULL
NULL
HKD Hong Kong dollar B 9 NULL NULL NULL
NULL
NULL NULL NULL NULL sgl Singapore S 10
NULL NULL NULL NULL MY Malaysia S 11
CN China B 12 NULL NULL NULL NULL

Regards,
Omavlana

Jul 20 '05 #2

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

Similar topics

4
1371
by: Denis St-Michel | last post by:
Hello All, Hope some Guru will be able to help me with this. Let's take this example table A ------------------------------------------------------------------------------- id | ...
1
2784
by: nuked | last post by:
I have a table that has values of variables for certain entities. The columns of interest are targetID, variableID, and valueID. A row (1, 5, 9) means that target number 1 has a value of 9 for...
7
9184
by: Andrew Mayo | last post by:
Here's a really weird one for any SQL Server gurus out there... We have observed (SQL Server 2000) scenarios where a stored procedure which (a) begins a transaction (b) inserts some rows into...
4
4090
by: jbm05 | last post by:
Hi, I'm curious about the computational complexity of a query I have. The query contains multiple nested self left joins, starting with a simple select, then doing a self left join with the...
10
3227
by: Rada Chirkova | last post by:
Hi, at NC State University, my students and I are working on a project called "self-organizing databases," please see description below. I would like to use an open-source database system for...
6
8587
by: John E | last post by:
I have a question about how to make records in a table reference other records in the same table.... Suppose I'm building a small database to track some basic information on several companies....
6
6284
by: davegb | last post by:
I'm trying to create a self-join table to show the relationship between employee and supervisor. In another thread, I was advised to create a SupervisorID in the employee table, a separate...
3
1508
by: sks | last post by:
I have a table that contains keywords (Varchars) each one mapped to a product. so the database schema is just an id column, product column and keyword column. I want to select the products that...
2
1775
by: Darragh | last post by:
Hi all! I'm having a bit of an issue making a self join in access (similar to the example explained on Allen Browne's excellent site - http://allenbrowne.com/ser-06.html). I've made the self...
36
2461
by: TC | last post by:
I've used Access for many years. Several times, I've encountered a bug which I refer to as the "Vanishing Joins" bug. When it happens, joins vanish randomly from queries. More specifically, all...
0
7225
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
7124
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
7385
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...
1
7046
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
4707
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
3195
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
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1558
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
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.