Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
How to create a SQL view and set up a browser based on it SQL views are a great way of looking at data on tables not available through the normal browsers. Below is just a really basic example of one, and assumes you have access to Sql Server Management Studio (SSMS) The ‘proper’ way to write a view is in Agresso > Settings > System Administration > Balance Tables > Database view definition However this is really inefficient as you’re limited to Asql (Agresso SQL) and also a certain number of characters. Its basically there as a tool for people who have very limited access to their database. The ctrl + shift + h trick in agresso is very handy (assuming you have access to the data dictionary) When you’re on a field, push all these together and it will give you the field name which *generally* you can search for in the data dictionary! Helpfully it doesn’t show you the table name. Below I had selected a cell in the TransNo column, see ‘active field’ The best way to create views is to create them directly on the database in my opinion, if you have access to SQL server management studio (SSMS) If you are creating stand alone reports then you will not have any problem at all. The issue comes when you want to create a browser on which you can expand base, bring in descriptions or link to other browsers. This is because a view is basically a pseudo table that is created each time the view is queried, so it needs to be told how to interact with other tables and this is done in the data model. For now I’ll just cover setting up a simple view, and then the menu item to access this. *Make sure you document ALL your views as Agresso sometimes deletes them during patches and updates etc!* Its is also useful to start the view name with UVI (User VIew) as it makes them easier to keep track of!) I will use a basic example demonstrate, in this case I just want to list cost centre, name + total expense. Start by creating the query in SSMS, because we’re creating the view as a stand alone table we need to make sure we bring in the description as we won’t have the code / text option in the browser. This is also good though as it allows us to sort on the description if we want! (Ever tried to sort by cost centre description when using code/text?? Its not possible!!) The first thing I do is a select * on the table to make sure I get the headings right! SELECT * from agltransact where 1=2 Obviously where 1=2 means it just returns headings without any data! Then build the query so: SELECT DISTINCT t.dim_1, sum(t.amount) as expense FROM agltransact t WHERE client='SD' GROUP BY t.dim_1 Note that the column names in the view will be whatever you alias your columns as in the select, so my amount column will be called ‘expense’ Now just join out to get the cost centre description SELECT DISTINCT t.dim_1, sum(t.amount) as expense, d.description FROM agltransact t LEFT OUTER JOIN agldimvalue d ON t.client=d.client AND t.dim_1=d.dim_value AND d.attribute_id='C1' WHERE t.client='SD' GROUP BY t.dim_1, d.description Which I know by checking back to a GL enquiry gives me the right results. To make this into a view its simply: CREATE VIEW uvidemo AS ( SELECT DISTINCT t.dim_1, sum(t.amount) as expense, d.description FROM agltransact t LEFT OUTER JOIN agldimvalue d ON t.client=d.client AND t.dim_1=d.dim_value AND d.attribute_id='C1' WHERE t.client='SD' and t.period BETWEEN '201001' AND '201002' GROUP BY t.dim_1, d.description ) Your view will now appear in SSMS under Server>Databases>database>views To add it into an Agresso (I use the cheat way) right click where you want it and ‘New Menu’ Give it a name, attach it to roles, click advanced and change the func.type to browse table, the program to agrcore and the argument to your view name! If you open the browser and there are no columns, its generally because you’ve tapped the view name in wrong (I do this quite regularly!) And hey presto there you go!