Hitesh Shah
23rd May 2009, 13:18
A new blog entry has been added:
Tips for Multi-company / Calculated items in MS SQL query
Tips for Multi-company / Calculated items in MS SQL query
If one is using SQL 2000/2005 and one wants to access the same from outside (say MS Excel or .net application or any other application) , one can use the SQL client in conjunction with following SQL tips.
Multi-company query
Though baan driver let’s user access data from same table from multiple companies using compnr specification, in the MS SQL backend the tables are separate with company suffix . If one is to combine the data from multiple companies for same table, Union operator is SQL query is the key. Using this operator also one may need to know from which company the data has originated . In Baan 4GL one can get this with ._compnr field selected . In MS SQL one needs to hard code the company constant expression in each SQL query combined with UNION operator . An example will illustrate this clearly.
Select t_leac as Ledger ,t_dbcr ‘Debit/Credit’,t_year as Year ,t_fprd as Period, t_amth as Amount , ‘300’ as company – Constant for company
From ttfgld106300
UNION
Select t_leac as Ledger ,t_dbcr ‘Debit/Credit’,t_year as Year ,t_fprd as Period, t_amth as Amount, ‘301’ as company – Constant for company
From ttfgld106301
This example will select data from tfgld106 of 300 and 301 company.
Tips for Multi-company / Calculated items in MS SQL query
Tips for Multi-company / Calculated items in MS SQL query
If one is using SQL 2000/2005 and one wants to access the same from outside (say MS Excel or .net application or any other application) , one can use the SQL client in conjunction with following SQL tips.
Multi-company query
Though baan driver let’s user access data from same table from multiple companies using compnr specification, in the MS SQL backend the tables are separate with company suffix . If one is to combine the data from multiple companies for same table, Union operator is SQL query is the key. Using this operator also one may need to know from which company the data has originated . In Baan 4GL one can get this with ._compnr field selected . In MS SQL one needs to hard code the company constant expression in each SQL query combined with UNION operator . An example will illustrate this clearly.
Select t_leac as Ledger ,t_dbcr ‘Debit/Credit’,t_year as Year ,t_fprd as Period, t_amth as Amount , ‘300’ as company – Constant for company
From ttfgld106300
UNION
Select t_leac as Ledger ,t_dbcr ‘Debit/Credit’,t_year as Year ,t_fprd as Period, t_amth as Amount, ‘301’ as company – Constant for company
From ttfgld106301
This example will select data from tfgld106 of 300 and 301 company.