PDA

View Full Version : Help on sql statement


ABC123

Anis
03-25-2008, 06:13 PM
I have a script on a form that runs an SQL statements to ZOOM in to detailed data for a summary record, but I need the WHERE statements to be filtered out to fields that show on the record displayed(summary record) ,
Do I have to set variables to hold the contents of the fields on the current displayed record ? or is there a more direct way,
Could the argument be a field name for example ?

Howard G. Cornett
03-26-2008, 11:26 AM
I am not totally clear on what you are doing, but if I understand properly, you can built a statement that is built on two tables while only selecting fields from one. Then you would be able to use the other table's fields in the WHERE statement.

If you give us an example of the SQL statement you are trying to create, maybe we can give you more helpful suggestions.

Howard

Anis
03-26-2008, 11:29 AM
I need the where statements on an sql statements to use the contents of a field on the form.
For example if I have a form that is displaying the account number 12345
I need the sql statements to say "where account = '12345'

If the record changes on the form and I play the script, the where changes to the new record displayed.

Howard G. Cornett
03-26-2008, 11:54 AM
Please post your script so I can see the context for the SQL statement. Then I should be able to help you further.

Howard

Steve Workings
03-26-2008, 12:46 PM
Here's an example that might help. In this case I've simply dimmed the variable in the script, but in your case it already exists for you to reference. I think the main question you have is how to reference the variable value within the SELECT statement.


dim MyFieldVar as c = "Nugget"

sqlStatement = <<%sql%
SELECT * FROM pet WHERE (name = '%sql%

sqlStatement = sqlStatement + MyFieldVar + "')"

flagResult = cn.Execute(sqlStatement)

Anis
03-26-2008, 01:15 PM
Steve;

How do I reference the variable as the contents of specific field showing in that speceific record.

I mean for account = 12345 which is displayed as the current record, if I go to record 2 I need that to change to the new content in the where statement.

A sample data base is attached, the "click for details" button should use the content of the filed Pty_Accnt in the where statement.

Selwyn Rabins
03-26-2008, 02:07 PM
I have a script on a form that runs an SQL statements to ZOOM in to detailed data for a summary record, but I need the WHERE statements to be filtered out to fields that show on the record displayed(summary record) ,
Do I have to set variables to hold the contents of the fields on the current displayed record ? or is there a more direct way,
Could the argument be a field name for example ?

you should not have to write any sql.

consider first the case where your application was based on native a5 tables. the xbasic that you would use to zoom in on a particular record would be something like

form.viewqueried("formaname","filterexpression")

where filterexpression is an xbasic filter expression.

now assume that 'formname' is based on an active link table.

nothing changes.

you still use this command to open the 'zoomed' view of a particular record:

form.viewqueried("formaname","filterexpression")


filterexpression is still an xbasic filter expression.

a5 automatically converts 'filterexpression' to a sql filter expression and opens the target form showing the record that you want.

in other words, you don't have to write any sql yourself.

Anis
03-26-2008, 03:02 PM
Selwyn;

The form is based on GROUPED records from the original SQL database,
The detailed button should go back and get the detailed records, that's why I think I need to write the SQL statement.

The method you suggested brings up the grouped (summary) records for the account.

gregz
03-26-2008, 03:46 PM
I have a 1,000,000 record table and its too slow when I go into the screen based upon a activeSQL table.
Is there a trick to opening a screen based upon a large table and not wait forever before I can hit the next record button?
greg

Selwyn Rabins
03-26-2008, 03:46 PM
Selwyn;

The form is based on GROUPED records from the original SQL database,
The detailed button should go back and get the detailed records, that's why I think I need to write the SQL statement.

The method you suggested brings up the grouped (summary) records for the account.

i don't have enough details to give you a complete answer, but based on the limited knowledge I have, I assume that you have a form or browse open that is on a record that has a value in some primary key field.

you want to then open another form that is filtered on that primary key value.


you could define an active link table that uses an argument. for example:


select * from mytable where primarykey = :whatkeyvalue


next define a form that is based on that active link table.


if you try to open that form from the control panel, you will notice that every time you try to open it, you are prompted for the value of whatkey.

when you zoom to the detail record, you want to open this form, and pass in the value of the current record primary key value so that there is no prompt.

this is done like this:


dim args as sql::arguments
args.add("whatkeyvalue",---read the value from the current record and set it here---)

f = form.view("formaname","","","","",args)

Selwyn Rabins
03-26-2008, 03:48 PM
I have a 1,000,000 record table and its too slow when I go into the screen based upon a activeSQL table.
Is there a trick to opening a screen based upon a large table and not wait forever before I can hit the next record button?
greg

put an argument in the select statement for the activelink table.
then when you open the active-link table, supply the argument value. that will filter the data on the server before any data is transferred to the client.

Anis
03-26-2008, 04:27 PM
That's exactly what I'm trying to do, now I don't know how to do this part:
args.add("whatkeyvalue",---read the value from the current record and set it here---)

How do I make the argument a primary key field content ? and how to bypass the prompt on the argument so once you click the script button it excutes the script.

Anis
03-26-2008, 05:13 PM
Thanks everyone I got it to work.

I mapped 5 arguments to field names thru action scripting and I created an active link with detail view.
I created a browse on the detail table.
I put the script on the summary form, once clicked it opens the detailed browse for the primary keys dispalyed.

gregz
03-27-2008, 10:01 AM
The problem is I don't know what record the users will want to look for. How can I filter it when the users will perform a search on a field value?
The field vaule can not be a primary key due to duplicate entries.
Greg

Selwyn Rabins
03-27-2008, 10:44 AM
The problem is I don't know what record the users will want to look for. How can I filter it when the users will perform a search on a field value?
The field vaule can not be a primary key due to duplicate entries.
Greg


you don't have to know it in advance. at runtime, the user selects something, or presses a button, etc. to open a form or browse that is based on the 1,000,000 row active-link table.

at that time, you set the argument value and then open the form or browse, and pass in the argument.

you will notice that the form.view() and browse.view() commands now take an optional argument of 'arguments' which allows you to pass in arguments.

for example,
1. your active link table has this sql statement
select * from orders where customerid = :whatcustomer


2. in the above sql, 'whatcustomer' is an argument.

3. you create a form called "showOrders" that is based on this active link table.

4. you have another form that shows a list of customers. this form has a button that opens the "showOrders" form. the control on this form that shows the customerId is called 'objCustId'.

5. the code in the button's onPush event is

dim custId as c
custId = objCustId.text
dim args as sql::arguments
args.add("whatcustomer",custId)
f = form.view("showOrders","","","","",args)


(in this example, I have assumed that the customerId field is a character value. It does not have to be. You would need to set the argument value with the correct data type. if it was numeric, for example, you would do this:

args.add("whatcustomer", convert_type(custId,"N") )