Author |
Topic |
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2006-08-03 : 02:47:27
|
Hi all,I Have A Table Like This Create Table Ai_Company_Level( Organisation_Code Varchar(10), Element_Code Varchar(10), From_Process_Period Int, To_Process_Period int, BS Varchar(3), HRA Varchar(3), MPA Varchar(3), LTA Varchar(3), MM Varchar(3), CON Varchar(3), ARINC Varchar(3), AR_ER Varchar(3), AR_DE Varchar(3), SA Varchar(3), MISCD Varchar(3), CD Varchar(3), PTAX Varchar(3), PF Varchar(3), ESIEE Varchar(3))Insert into Ai_Company_LevelSelect 'RSWMLNJA' ,'PTAX' ,'1' ,'2' ,'YES' ,'YES' ,'YES' ,'NO' ,'YES' ,'YES' ,'YES' ,'YES' ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULLCreate Table Ai_Elemnts( Organisation_Code Varchar(10), Element_Code Varchar(10), From_Process_Period Int, To_Process_Period int,)insert into Ai_Elemnts Select 'RSWMLNJA' ,'BS' ,'1' ,'2'Union all Select 'RSWMLNJA' ,'HRA' ,'1' ,'2'Union all Select 'RSWMLNJA' ,'MPA' ,'1' ,'2'Union all Select 'RSWMLNJA' ,'LTA' ,'1' ,'2'Union all Select 'RSWMLNJA' ,'MM' ,'1' ,'2'Union all Select 'RSWMLNJA' ,'CON' ,'1' ,'2'Union all Select 'RSWMLNJA' ,'ARINC' ,'1' ,'2'Union all Select 'RSWMLNJA' ,'AR_ER' ,'1' ,'2'Union all Select 'RSWMLNJA' ,'AR_DE' ,'1' ,'2'Union all Select 'RSWMLNJA' ,'SA' ,'1' ,'2'Union all Select 'RSWMLNJA' ,'MISCD' ,'1' ,'2'Union all Select 'RSWMLNJA' ,'CD' ,'1' ,'2'Union all Select 'RSWMLNJA' ,'PTAX' ,'1' ,'2'Union all Select 'RSWMLNJA' ,'PF' ,'1' ,'2'Union all Select 'RSWMLNJA' ,'ESIEE' ,'1' ,'2'What i want isi want to check the Element_Code(Ai_Elemnts table) column in Ai_Company_Level columns thats is bs ,HRA.. etcif that column value is yes means i need to take the elementi.e Ai_Elemnts.row value = Ai_Company_Level.column_nameHow can i do thisplease help mePulling my hair outThanksKK |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-08-03 : 02:54:50
|
is the Ai_Company_Level.Element_Code related to Ai_Elements.Element_Code ? KH |
 |
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2006-08-03 : 03:06:49
|
yes , |
 |
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2006-08-03 : 03:12:00
|
The Ai_Company_level Table Have The Values Like Organisation_Code Element_Code From_Process_Period To_Process_Period BS HRA MPA LTA MM CON ARINC AR_ER AR_DE SA MISCD CD PTAX PF ESIEERSWMLNJA PTAX 1 0 YES YES YES NO YES YES YES YES RSWMLNJA MM 1 0 YES YES YES YES YES YES YES YES (2 row(s) affected) |
 |
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2006-08-03 : 03:13:18
|
Jen Expliain me MorePlease--KK |
 |
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2006-08-03 : 03:15:34
|
And The Ai_Elemnts Have the values likeOrganisation_Code Element_Code From_Process_Period To_Process_Period ----------------- ------------ ------------------- ----------------- RSWMLNJA BS 1 2RSWMLNJA HRA 1 2RSWMLNJA MPA 1 2RSWMLNJA LTA 1 2RSWMLNJA MM 1 2RSWMLNJA CON 1 2RSWMLNJA ARINC 1 2RSWMLNJA AR_ER 1 2RSWMLNJA AR_DE 1 2RSWMLNJA SA 1 2RSWMLNJA MISCD 1 2RSWMLNJA CD 1 2RSWMLNJA PTAX 1 2RSWMLNJA PF 1 2RSWMLNJA ESIEE 1 2(15 row(s) affected) |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-08-03 : 03:24:12
|
quote: i want to check the Element_Code(Ai_Elemnts table) column in Ai_Company_Level columns thats is bs ,HRA.. etcif that column value is yes means i need to take the element
so you need to do this ?Ai_Company_Level INNER JOIN Ai_ElementsON Ai_Company_Level.Element_Code = Ai_Elements.Element_Code i am a bit confuse with your statement here. KH |
 |
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2006-08-03 : 03:36:25
|
ah...I see what you mean...but what exactly do you need to do? take out in what sense?--------------------keeping it simple... |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-08-03 : 03:47:35
|
Table Ai_Company_Level does not look normalize. And hence you have the problem joining.Here is a view that transpose the tablecreate view Ai_Co_lvlas select Organisation_Code, Element_Code, From_Process_Period, To_Process_Period, 'BS' as E_Code, BS as E_Valuefrom Ai_Company_Levelunion allselect Organisation_Code, Element_Code, From_Process_Period, To_Process_Period, 'HRA' as E_Code, HRA as E_Valuefrom Ai_Company_Levelunion allselect Organisation_Code, Element_Code, From_Process_Period, To_Process_Period, 'MPA' as E_Code, MPA as E_Valuefrom Ai_Company_Level Then you can JOINing it to the Ai_Elements table. Is this what you need to do ? KH |
 |
|
|
|
|