So I have a dimension table like this:
create table my_dimension_table
(
main_key int NOT NULL,
linked_id int,
CONSTRAINT C_PRIMARY PRIMARY KEY (main_key) ENABLED
)
and my flattened table is like so
create table my_flattened_table
(
mod_date date,
some_value varchar(50),
main_key int NOT NULL,
linked_key. DEFAULT USING (SELECT CASE WHEN (my_dimension_table.linked_id IS NULL) THEN my_dimension_table.main_key ELSE my_dimension_table.linked_id END
FROM my_dimension_table
WHERE (my_flattened_table.main_key = my_dimension_table.main_key)),
)
This doesn't seem to work. Is there something similar I can do to achieve this?
So background on what I'm trying to do here:
Basically we perform complex queries on my_flattened_table.linked_key and do many group by. This field needs to be equal to my_dimension_table.linked_id when its not null, otherwise equal to my_dimension_table.main_key.
Any suggestions appreciated!