Tuesday 5 February 2013

Shortcut and Alias shortcut explained


Hi Guys

Below is a explaination on alias shortcut and shortcut

I  have created shortcut (reference ) to employee history created join between employee history and shortcut and published the model



Now what is interesting in this .

Notice the behavior of the generated sql and you will neve has issue of differentiating between Shortcut and alias .

See its picking values from only one table Position Department .as if the shortcut is only for our understanding




select "POSITION_DEPARTMENT"."POSITION_CODE" "POSITION_CODE", "POSITION_DEPARTMENT"."DEPARTMENT_CODE" "DEPARTMENT_CODE"
 from "GOSALESHR"."POSITION_DEPARTMENT" "POSITION_DEPARTMENT"


Now Alias Shortcut 







Look at the sql generated 


select "Alias_to_POSITION_DEPARTMENT"."POSITION_CODE" "POSITION_CODE", "POSITION_DEPARTMENT"."DEPARTMENT_CODE" "DEPARTMENT_CODE"
 from "GOSALESHR"."POSITION_DEPARTMENT" "Alias_to_POSITION_DEPARTMENT", "GOSALESHR"."POSITION_DEPARTMENT" "POSITION_DEPARTMENT", "GOSALESHR"."EMPLOYEE_HISTORY" "EMPLOYEE_HISTORY"
 where "Alias_to_POSITION_DEPARTMENT"."POSITION_CODE"="EMPLOYEE_HISTORY"."POSITION_CODE" and "EMPLOYEE_HISTORY"."POSITION_CODE"="POSITION_DEPARTMENT"."POSITION_CODE"


Comment 

It treats the alias shortcut as a separate new table .Its same as creating alias in oracle statement

Similar to below oracle statement 

select * from emp a , dept b
where a .dept_id =b.dept_id

here a , b are alias to emp and dept table respectively .


Difference between Model query subject and Alias 

The key difference between model objects and shortcuts is that model objects give you the freedom to include or exclude items and to rename them. You may choose to use model objects instead of shortcuts if you need to limit the query items included or to change the names of items.


IBM Link stating difference

Model Query subjects 

If you create a new model query subject on Position department .and take postion code from model query subject and department code from original Position department you will see that cognos can recognise its the same table and below is its query .It works like shortcut(reference) 

select "POSITION_DEPARTMENT"."POSITION_CODE" "POSITION_CODE", "POSITION_DEPARTMENT"."DEPARTMENT_CODE" "DEPARTMENT_CODE" from "GOSALESHR"."POSITION_DEPARTMENT" "POSITION_DEPARTMENT"


However as soon as you create relationship to this model query subject it behave as Alias shortcut 

select "New_Query_Subject"."POSITION_CODE" "POSITION_CODE", "POSITION_DEPARTMENT"."DEPARTMENT_CODE" "DEPARTMENT_CODE" from "GOSALESHR"."POSITION_DEPARTMENT" "New_Query_Subject", "GOSALESHR"."POSITION_DEPARTMENT" "POSITION_DEPARTMENT", "GOSALESHR"."EMPLOYEE_HISTORY" "EMPLOYEE_HISTORY" where "New_Query_Subject"."POSITION_CODE"="EMPLOYEE_HISTORY"."POSITION_CODE" and "POSITION_DEPARTMENT"."POSITION_CODE"="EMPLOYEE_HISTORY"."POSITION_CODE"


Very Important note -

Alias shortcut as name suggest is a shortcut any changes that you make to original will be reflected like change of column name will change column name in alias shortcut not the case with model query subject

2) When you create a relationship to model query subject it will ask whether you want to replicate all the original relationships .Like suppose you create model query subject of product it will ask if you want all product relationship to be assigned to model query subject .So if you say yes the model query subject will behave just as original product with your new relationship . This is not the case with alias shortcut


I hope this is one of the best explanation available out there .


2 comments: