Powerbuilder change dynamically datawindow select - powerbuilder

I have two radio buttons and one datawindow. By selecting one of them, the datawindow select must change dynamically. For example, when rb1 is checked the datawindow select is "select name, surname, age from Table1" and when rb2 is checked datawindow select is "select name, surname, age from Table2". How can i do that?

There are many ways to skin a cat but it's not uncommon to see either of these strategies used. The first might be okay if you want both to look similar in presentation. Second might be cleaner if there is the user interface looks different for each one.
Use SetSQLSelect function (or)
Swap out one of two datawindow objects based on radio button position.

If the select part of the sql (everything before from) is exactly the same you can use datawindow.setsqlselect( sqlstring )
You can make 2 datawindow objects and change the dataobject of the datawindow on the window dw.dataobject = string (the connection to the DB will be lost so you have to set the transaction object again before executing the retrieve)
You can also have 2 datawindows on the window and play with the dw.visible = boolean property


Why datawindow query does not refresh column specifications?

The Query behind datawindow is Select * from MyTable. I changed the table and added another column. When i retrieve the datawindow in design mode, it does not show me the new column i added in MyTable
I assume that Select * from MyTable will not require editing datawindow in design mode and every change in database table will update the datawindow design as well.
How do i get all the columns in column specifications without changing datawindow in design mode to manually add the column in detail area of the datawindow?
PowerBuilder 12.5 /
MSSQL Server 2008
If you want to do this, you can use the create method of your datawindow control:
String new_sql, new_syntax, errorsyntaxfromSQL, errorcreate
new_sql = 'SELECT * from Mytable'
new_syntax = SQLCA.SyntaxFromSQL(new_sql, 'Style(Type=Form)', error_syntaxfromSQL)
// Generate new DataWindow
dw_new.Create(new_syntax, error_create)
It is up to you to test the possible errors.
I assume that Select * from MyTable will not require editing datawindow in design mode and every change in database table will update the datawindow design as well.
This is not a valid assumption. If you change the underlying table columns either by adding, removing, or datatypes, you have to bring any datawindow objects which reference that table (by reference I mean you want to use the new column or had used an old column or one with the changed datatype) back into the editor to have them reflected in that dwo.
Another option is to edit the source of the datawindow object but this would only be for trivial updates (like you expanded a varchar field from 10 to 20).

Is it possible to edit field values in DBGrid connected to a dataset from a FULL JOIN table SELECT query?

I have this query
T1 ON T1.Usr = T2.Guid
Is it possible to edit this result from DBGrid ?
I want to add Fields T1.Add and T1.Edit to T1 table
if they are not already there
and change their values.
Depending on the used components you could use BeforePost (doing your actions and requery), ModifySQL/insertSQL for IBDataSet, OpdateObject TQuery, etc.
Another way would by using " INSTEAD OF triggers" for a persitant view.

Reordering ADO Recordset columns

I have a recordset with columns
And I need to reorder this columns to
This recordset is used to fill an Excel spreadsheet and need to change the recordset column order because reordering in Excel is to slow.
Any idea?
Right click on your Table/Query, select Field Editor.
If there are not fields, press CTRL+F.
Drag by mouse fields changing order as you want.
Or, if you have a Query, you may change select field order: select Field2, Field1 from Table.
Or you may physicaly redesign field order in your table/view/procedure.

Is it possible to select a field from a table, but override it with a new value in the select statement?

I am creating a view like this:
Let's say I originally have this:
select * from mydb.mytable
mydb.mytable has a field called FirstName, but I want to transform its value in the select statement. Conceptually, I want to do this:
select *, upper(firstname) firstname from mydb.mytable
The problem is that * is already returning FirstName, so adding another column of the same name to the select breaks the SQL. To get it to work, I have to list each field like this:
select upper(firstname) firstname, lastname, city, state, zip
This is just one example, but the table I really want to use this with has 30+ columns. I don't like the idea of having to list out each column because adding a new field to the table means I have to modify the SQL (ordinal field position doesn't matter).
Well, that's the way SQL is designed, it's not a specific Teradata problem.
You want something like "select * but firstname" and no DBMS has implemented such a syntax.
Btw, one of (my) basic SQL rules is: never write "SELECT *" :-)
As dnoeth says, that's just how SQL works. Also, I'd reinforce his comment about never using select *, especially in a view.
To address concerns like this, I keep the table and view DDL together in code. Whenever you change the table definition, you change the view definition at the same time. That way, whenever you add or remove columns from your table (your stated concern), your view always remains current.

Tweaking a TDbGrid

I am taking my first stumbling steps into DB aware controls (any good tutorials?).
I have a MySql table with 6 columns and have managed to load it into a TDbGrid.
One of the columns however is an index into another table. It is a bar code and, rather than display that, I would like to display the product name associated with it.
How do I do that?
(and can I hide the "gutter" (?) down the left whcih shows the current row?)
You should always perform a join from the SQL side, it's much easier then doing it programaticaly
Such as:
SELECT mytable.id, mytable.column1, another_table.barcode
FROM mytable
JOIN another_table ON another_table.id = mytable.barcode_id
To remove gutter you need to uncheck the DBGrid property dgIndicator in Options.
As for "DB-Aware controls" you should try delphi help.
Instead of a table, make use of a query. Then, use a join to select the product name with it, like this:
YourTable t
INNER JOIN Product p on p.barcode = t.barcode
I use t.*, because I don't know the exact columns. In practise, I would not use select *, but specify specific columns instead. If you are going to use * anyway, you can hide speicfic columns by setting the Visible property of the TField object in the dataset/query to False.
I don't know which components you are using to connect to the table, but most of them do have a query-counterpart that allows you to insert SQL instead of a table name.
The gutter can be hidden by going to the property Options in the object inspector, expand it, and set dgIndicator to False.
Just for the record: with ISAM databases like Paradox and DBF typical solution would be so-called master-detail tables relations and it still might work for SQL. Though it would be very inefficient and slow. You'd definitely read som books about SQL.
Use a TQuery component instead of a TTable and set SQL property using the suggested select statements above. If you just add the columns you want to display in your sql statement, you get the result as expected. As for "gutter" you would have to hack the grid in some way at runtime.