APEX 4.1 SQL Query using a page item to define FROM - plsql

I am trying to utilize a single tabular form to handle a couple minor tables since I cannot have multiple updateable reports on a single page. The easiest way I could figure to adjust what table I was modifying was to use a select list to choose which table I am viewing/editing.
The select list contains a display of "Supervisor" and "School"
resulting in SUPERVISOR and SCHOOL respectively
the items name is P8_TABLE
Region Source:
select *
from #OWNER#."G06_" || :P8_TABLE
The tables are named G06_SUPERVISOR and G06_SCHOOL
However the query returns:
ORA-00933: SQL command not properly ended

I'm afraid that this won't work. As far as I can tell, tabular form is to be based on one table only (i.e. you can't have a JOIN in there; even if you're displaying values from some other table, you'd rather create functions which would return those values).
That being said, principle you'd like to use means that tabular form underlying table is unknown (as it can vary, depending on what you select in P8_TABLE select list item), which - in turn - means that column names also differ (unless all of those tables share the same column list).
If we presume that above is correct, then I'd suggest you to abandon that approach and maintain every "minor table" on its own tabular form page. It will be just a little bit more typing & clicking, but I wouldn't worry about it.
Hopefully, someone else knows how to do it the way you'd want it to.

You cant make a tabular form query source dynamic. And since the two tables you want to be displayed and be updatable doesnt have common number and usage of their columns, the only way I can think of is separating the two tables and diplaying one tabular form for each table. Though, Apex 4.1 or even the latest Apex 5 doesnt allow multiple tabular form, you can make this possible by using javascript's iframe. You'll need to use javascript since you want to modify the interface of the report/page.

Related

Is it possible to filter the list of fields when outputting a Full Dataset?

I have a DataTable that I'm passing to a FlexCel report. It contains a variable number of columns, so I'm using the Full Dataset feature (e.g. <#table_name.*>).
However, only a subset of the fields are dynamically generated (I have a variable number of attachments). The column name for each attachment field starts with a common word (e.g. "Attachment0", "Attachment1", etc).
What I would like to do is output the known finite set of fields and then the variable number of attachments. It would be nice if I could write something like <#table_name.Attachment*> (and <#table_name.Attachment**>). Is there any way in FlexCel Reports I can achieve the same result?
A side benefit to such a solution means that I could keep the formatting for the known/finite set of fields.
Update
I added place holder columns to the document, each with a <#delete column> tag, so that the un-wanted columns/data are removed.
Although this works, it's not ideal. For example, if I want to see how the columns fit in the page width (in print preview), then I need to hide the columns. Then I have to remember to un-hide them again, so other developers can see/understand my handy work.
It would be much more straight forward if I could filter the fields before they're output to the document.
I realised there's an alternate way around this problem. I broke up the data into two sets of data - <#table_name.*> and <#table_name_attachments.*>.
The fixed set of fields are in the first table and the variable set of fields is in the second table (all the "Attachment*" fields). When the report is run, I place them next to each other (in the same order) in the same worksheet. This means I have two table ranges - "_table_name_" and "_table_name_attachments_" on the one sheet.
Now I'm able to run my print preview without hiding/re-showing the columns-to-be-deleted. I've also eliminated human error - it was all to easy to accidentally set the wrong number of padded/delete columns.

Database schema design options

I'm struggling to decide what database schema to use. One large table, or many small (though more difficult to manage).
I have 10 templates each with their own text fields. I am trying to store the text for the templates in a database and then when the web page is called I will show the correct text in the html template. Because a mixture of these templates are to be in a sequence of screens where you can navigate backwards or forwards, I need to be able to sequence them, I can only think of adding a page_number column. I also would like to re-order them and delete them as necessary using the page_number column.
I was planning to do all this in a web application without the need for a standard folder/web page structure, like a small CMS system.
option 1,
I can create one large table with many columns, lot's of which will be empty, over half with each row. Is this bad?
option 2,
I could create many tables using only the relevant template columns required.
The problem I see with this, is the headache of repopulating a column in each table when I delete a row, because I need to re-sequence a column that represents page numbers. Which I reduce if I use one large table.
I've thought of moving page numbers into another table called page_order but I cannot think of a way to maintain an effective relationship between the other tables if I make changes.
I'm yet to figure out how to re-sequence a column in a database when a row is deleted. Surely this is a common problem!?
Thanks for taking the time to help!
Have one table that contains one row per template. It might look like:
id (INT, auto-increment)
page_order (INT, unique key here, so pages cannot have the same number)
field1 (STRING, name of the text field)
value1 (STRING, contents of the text field)
field2
value2
Then you have to decide the maximum fields that any page can have (N) and keep adding field/value columns up to N.
The advantage of this is you have one table that isn't sparsely populated (as long as the templates have about the same number of fields, even if the names of those fields are different).
If you want to make an improvement to his (maybe not necessary for a small amount of data) you could change field to an INT id and connect it to a lookup table that contains (field_id, field_name).

Creating an expandable grid in MVC3 - data modelling

I am trying to create an expandable grid in MVC3. This is a follow up question to this .
Basically I have a complicated sql query that I need to use to populate a set of fields in a grid in MVC3. Also the grid elements must be expandable and on expansion should show additional data.
For example
I have two sql queries
Query A
select * from large tables joined
Query B
select data from selected row in query A
Query A represents my first query which I should use to populate the grid. On expansion of the grid I have to show the additional data by expanding the row from A with the query B.
I am creating a view model with all the fields I need in the first row of the grid that I can pass to the view.
Questions:
1.) How do I directly use sql to pass the data into the views instead of joining the models
2.) How do I make the grid expandable to show additional data?
3.) How do I model my sql, do I create one query for both and then selectively show data?
Caveat: MVC3 noob
Answers inline
Questions:
1.) How do I directly use sql to pass the data into the views instead of joining the models
This depends, either you pass in everything up front and write out hidden fields, or a hidden JSON object containing all the data and when the field is expanded, show it. so that is: Render all the data in your grid and hide each item until you need it, or dynamically load it from an array and show it when the user expands. You could also dynamically grab the required data when a user clicks on a row, but then you'd need to show a wait image while you grab the data by ajax (which would be fairly easy with mvc)
2.) How do I make the grid expandable to show additional data?
Plenty of expandable html grid results on the net :) Depend show you want to hide/show it.
3.) How do I model my sql, do I create one query for both and then selectively
This depends on the approach in 1 above. If you use ajax, you'd be returning one row at a time. In the other scenario you can have two queries you then merge into two view models or you join query A results with query b if theres a 1-1 mapping, assuming there isn't though so make two calls. Again, this is up to you. Do you want to pass all that data up front if the user will only expand two rows? not likely, in that case I like the ajax approach.

Trying to get a text box in access to display the latest row in a query on button press

I have this code for the text box Control Source in Access:
=DLookUp("[Lot Number]","[Lot Number Generator Table Query]")
but that will only display the first row generated in the query. I need to get the latest one generated displayed. I've tried switching the ascending/descending order with no change.
Assuming LotNumber is sequential and that there are two tables to consider, try:
=DLookUp("[Lot Number]","[Lot Number Generator Table Query]","[Lot Number]=" &
Dmax("[Lot Number]","[Some Table]"))
Or much more simply, if there is only one table:
=Dmax("[Lot Number]","[Lot Number Generator Table Query]")
This is not safe in a multiuser environment or when Lot Number is an autonumber.
See also Domain Aggregate Functions

Displaying data with ASP.NET

I have a tbl_categories and a tbl_items. I want to display tbl_categories in a horizontal manner and list objects from tbl_items vertically below each category name. I am confused how to get all this data using TSQL stored procedures and displaying them using ASP.NET native controls.
Columns with headers of category names. rows of items keyed with category_id.
The db is set up correctly. It is the ASP.NET controls I have trouble with.
I would use a Repeater myself, and make it output an HTML Table. The categories row would be in the HeaderTemplate, the closing tags in the FooterTemplate, and the actual data inside the ItemTemplate
http://blogs.sitepoint.com/asp-net-repeater-control/
The best way to handle this is to setup business objects which support the data in a way you wish to present it, which may not always be the way it is handled by your database.
Then you can use those objects directly to bind or feed data into the UI.
You could use Pivot to do that. See this referece http://msdn.microsoft.com/en-us/library/ms177410.aspx

Resources