Friday, March 23, 2012

outer join

I need help with a outer join.

I have a table called raw_data_info ..
raw_data_id raw_data_name
1 net income
2 net assets

I have another table called raw_data
raw_data_id report_date amount
1 2/28/2000 50

I need to write a sql statement that will return the below

raw_data_name amount
net income 50
net assets

I want a blank for net assets.

Is this possible?It is possible:

select a.raw_data_name, b.amount
from
raw_data_info a, outer raw_data b
where
a.raw_data_id = b._raw_data_id

you just have to use the outer on the table that you want to get nulls from :)|||I am sorry. I left one column out. I didn't think it mattered, but I see it does now. I am doing this in Access.

The tables should be -- raw_data_info
raw_data_id -- raw_data_name
1 -- net income
2 -- net assets

I have another table called raw_data
raw_data_id -- report_date -- cmpy_num -- amount
1 -- 2/28/2000 -- 9999 -- 50
1 -- 2/28/2000 -- 8888 -- 100

I tired (but it didn't work) --

SELECT I.mdy_raw_data_name, D.amount
FROM raw_data_info AS I LEFT JOIN raw_data AS D ON I.raw_data_id=D.raw_data_id
WHERE (report_date=#2/28/1999# Or report_date Is Null)

Is there any way to return --
raw_data_name -- amount -- cmpy_num
net income -- 50 -- 9999
net assets -- -- 9999
net income -- 100 -- 8888
net assets -- -- 8888|||select I.mdy_raw_data_name
, D.amount
from raw_data_info AS I
left outer
join raw_data AS D
on (
I.raw_data_id = D.raw_data_id
and iif(isnull(D.report_date)
,#2/28/1999#
,D.report_date) = #2/28/1999#
)|||Thank you so much!!sql

No comments:

Post a Comment