powerbuilder datawindow / sql query...

how can i use one datawindow in order sql query to be displayed in it?

I have two buttons on a form. According to the button you press different output will show up in the same datawindow. The same table from an oracle database will be used. Only one field is going to be changed.

query1: select that from there where field=10
query2: select that from there where field=20


is this somehow possible?

The datawindow will be the same.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

A simple option would be to select field1,field2 from there where field =:as_argument.

Then based on the argument( if it is always 10 or 20 ) or based on the clicked button ( you could pass some distinct value) based on which you could then make visible/invisible the field and the header text.


Both text2 and output2 will be overlapping text1 and output1 respectively.
Just set the visible propert to 1 or 0 based on that condition of whichevr button is selectd
stefanosnAuthor Commented:

these two lines i use to call the datawindow from the first button
the query created with teh wizard...

how can i define on the second button what query i want to run?
i have to do it from the wizard again and somehow call it?

Are you asking about retrieval arguments?  All columns in the result set and where clause are the same and you just want the criteria to have a different value?

In the datawindow painter when defining or editing the SQL, on the menu go to Design->Retrieval Arguments.  You can define as many as you want.  Then, when defining the WHERE clause, you can put :argumentName in place of the value.
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

stefanosnAuthor Commented:
under the second button what should i write? to call the second argument
stefanosnAuthor Commented:
i have a query

select username from users where a=1
select username from users where a=2

these two queries

i want the first query to run if i press the first button
i want the second query to run if i press the second button


the output will show on the same datawindow...according to the button i press

is this possible?
your retrieval will be with some arguments. So define a retreival argument in the sql.
Your sql query would look like
select field1,field2 from there where field =:as_argument.

In the first button retrieve as
dw_1.retrieve(as_argument.) and similarly in the second button you will be having
So basically retrieve passing an argument.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Of course!
In the datawindow you need to define a retrieval argument: click on the SQL button and then in the menu Design->Retrieval Arguments and create an argument called as you want for example "my_value" and select the type of data then, if you are in the graphic view select the menu View->Where and in column select the field of your table wich will be the condition for the retrieve (a in your case), in operator '=' and in value write :my_value
Your query must be:
select username from users where a=:my_value in the syntaxis view of the datawindow

Then in the button 1 write this code:
and in the button 2 write:

Do the following:

1. Open your window where you have datawindow and two buttons.
2. Now place your mouse on the datawindow and click the right mouse button.
3. Now select the modify datawindow from popup menu
4. Now select the sql button from the toolbar
5. Now select 'retrieval arguments' from menu 'Design'.
6. give the retrieval argument say ret_value as number or as you need
7. Now from the same menu 'Design' select convert to syntax
8. Here you will find the syntax and you will see the argument WHERE this = that (If not then write)
where column_name = :ret_value (You can do it also in Graphic mode. You can see in lower area some tabs as Sort Where Group Having etc. here you can select where and select the column and then in the value with the right mouse button select the argument and give ret_value with double click when you will see the given value in the retrieval arguments.
9. (if you are in syntax mode then only)Now menu 'design' and select convert to graphic
10. in the constructor event of you datawindow write:
11. In your button one clicked event write:

Long  ll_retvalue

ll_retvalue = 1 //or which value you want
dw_1.Retrieve(ll_retvalue) //which value you have for button 1

//do for the button 2 also the same
Long  ll_retvalue

ll_retvalue = 2

dw_2.Retrieve(ll_retvalue) //which value you have for button 2

If you any question please let me know.


Best regards

It maight be better to use a filter approach.  You can retrieve the data only once, apply the filter, then display the results.  Could be quicker and definitely cheaper with respect to database connections/overhead.

Create a function that has string argument and returns an integer

Parent.f_dwfilter ( "value" )  // pass either the 1 or 2

Function f_dwfilter
string ls_avalue //this could be integer, long, etc, depending on the value being passed - make sure that
                       //that you change the argument type
integer li_returncode

ls_avalue = as_avalue

dw_1.SetRedraw ( False )
string ls_dwFilter

ls_dwFilter = "a= '" + ls_avalue + "' "

li_returncode = dw_1.Filter( )

dw_1.SetReDraw ( True )

Return li_returncode

This is off the top of my head, but it should work.  Please let me know if you have any more questions.  the only caveat to this, is that if data changes after the data window has been retrieved, you will not see that data.  But as it seems that this is a display window only, then this should work faster.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.