Alpha Video Training
Results 1 to 15 of 15

Thread: Help on sql statement

  1. #1
    Member
    Real Name
    Anis Fakhoury
    Join Date
    Jun 2000
    Posts
    513

    Default Help on sql statement

    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 ?

  2. #2
    VAR Howard G. Cornett's Avatar
    Real Name
    Howard Cornett
    Join Date
    Feb 2003
    Location
    Lexington, MA
    Posts
    666

    Default Re: Help on sql statement

    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
    Howard G. Cornett, Independent Consultant

  3. #3
    Member
    Real Name
    Anis Fakhoury
    Join Date
    Jun 2000
    Posts
    513

    Default Re: Help on sql statement

    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.

  4. #4
    VAR Howard G. Cornett's Avatar
    Real Name
    Howard Cornett
    Join Date
    Feb 2003
    Location
    Lexington, MA
    Posts
    666

    Default Re: Help on sql statement

    Please post your script so I can see the context for the SQL statement. Then I should be able to help you further.

    Howard
    Howard G. Cornett, Independent Consultant

  5. #5
    Volunteer Moderator Steve Workings's Avatar
    Real Name
    Steve Workings
    Join Date
    Apr 2000
    Location
    The Dreaded Chair
    Posts
    5,639

    Default Re: Help on sql statement

    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.

    Code:
    dim MyFieldVar as c = "Nugget"
    
    sqlStatement = <<%sql%
    SELECT *  FROM pet  WHERE (name = '%sql%
    
    sqlStatement = sqlStatement + MyFieldVar + "')"
    
    flagResult = cn.Execute(sqlStatement)
    -Steve


  6. #6
    Member
    Real Name
    Anis Fakhoury
    Join Date
    Jun 2000
    Posts
    513

    Default Re: Help on sql statement

    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.

  7. #7
    Alpha Software Employee Selwyn Rabins's Avatar
    Real Name
    Selwyn Rabins
    Join Date
    Mar 2000
    Location
    Boston, MA
    Posts
    5,310

    Default Re: Help on sql statement

    Quote Originally Posted by Anis View Post
    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.

  8. #8
    Member
    Real Name
    Anis Fakhoury
    Join Date
    Jun 2000
    Posts
    513

    Default Re: Help on sql statement

    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.

  9. #9
    Member
    Real Name
    Gregory Zilliox
    Join Date
    Sep 2005
    Location
    Lewiston, NY
    Posts
    202

    Default Re: Help on sql statement

    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

  10. #10
    Alpha Software Employee Selwyn Rabins's Avatar
    Real Name
    Selwyn Rabins
    Join Date
    Mar 2000
    Location
    Boston, MA
    Posts
    5,310

    Default Re: Help on sql statement

    Quote Originally Posted by Anis View Post
    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)

  11. #11
    Alpha Software Employee Selwyn Rabins's Avatar
    Real Name
    Selwyn Rabins
    Join Date
    Mar 2000
    Location
    Boston, MA
    Posts
    5,310

    Default Re: Help on sql statement

    Quote Originally Posted by gregz View Post
    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.

  12. #12
    Member
    Real Name
    Anis Fakhoury
    Join Date
    Jun 2000
    Posts
    513

    Default Re: Help on sql statement

    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.

  13. #13
    Member
    Real Name
    Anis Fakhoury
    Join Date
    Jun 2000
    Posts
    513

    Default Re: Help on sql statement

    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.

  14. #14
    Member
    Real Name
    Gregory Zilliox
    Join Date
    Sep 2005
    Location
    Lewiston, NY
    Posts
    202

    Default Re: Help on sql statement

    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

  15. #15
    Alpha Software Employee Selwyn Rabins's Avatar
    Real Name
    Selwyn Rabins
    Join Date
    Mar 2000
    Location
    Boston, MA
    Posts
    5,310

    Default Re: Help on sql statement

    Quote Originally Posted by gregz View Post
    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") )

Similar Threads

  1. help with sql statement
    By lmarini in forum QReportBuilder
    Replies: 2
    Last Post: 03-24-2008, 12:08 PM
  2. help with sql statement
    By lmarini in forum Alpha Five Version 9 - Desktop Applications
    Replies: 1
    Last Post: 03-23-2008, 10:22 PM
  3. using varaible in SQL select statement
    By Anis in forum Alpha Five Version 8
    Replies: 2
    Last Post: 12-26-2007, 02:20 PM
  4. sql query statement?
    By ktjia@ampmservice.com in forum Alpha Five Version 8
    Replies: 5
    Last Post: 10-17-2007, 11:21 PM
  5. SQL select statement (Help) (:-0>
    By Hansolo in forum Web Application Server v6
    Replies: 4
    Last Post: 03-17-2005, 06:12 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •