Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to use the SELECT-command with empty values
Message
From
23/10/1998 06:27:35
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
22/10/1998 16:07:40
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00149479
Message ID:
00149757
Views:
23
>>>Hello,
>>>
>>>I am using Visual FoxPro 6.0 and I am making a search-form. On the form there are 8 textboxes, 1 button and a grid. If I fill in the textboxes and push the search-button a select-command is being executed and the results are put in a cursor with the following command:
>>>
>>>SELECT <...> FROM <...> INTO CURSOR cursorname WHERE <...>
>>>
>>>The grid is then using the cursor to show the results.
>>>
>>>I am using one select-command to search in the tables for the values in all the textboxes. The problem is that if I leave a textbox empty, the select-command is searching for empty fields. Is it possible not to search for empty textboxes with one select-command?
>>>
>>>Thank you for your time.
>>A simple way of doing that is building a generic SQL. It would be fast too if fields are indexed. Build your SQL like this :
* nMinVal and nMaxVal could be hardcoded, ref'd etc
>>cSQL = "select ... from "+;
>>"FROM <...> INTO CURSOR cursorname "+;
>>"WHERE myVal1 = trim(thisform.textbox1.value) "+;
>>" and myVal2 between "+;
>>"iif(empty(thisform.textbox2.value),nMinVal,thisform.textbox2.value) "+;
>>"and iif(empty(thisform.textbox2.value),nMaxVal,thisform.textbox2.value) "+;
>>" and myVal3 between "+;
>>"iif(empty(thisform.textbox3.value),{},thisform.textbox3.value) "+;
>>"and iif(empty(thisform.textbox3.value),date(),thisform.textbox3.value) "+;
>>....
>>thisform.searchgrid.recordsource = cSQL
>>thisform.searchgrid.recordsourcetype = SQL
>>*Button.click
>>thisform.searchgrid.refresh
Cetin
>
>Thank you very much for your answer. I have tried it, but the grid stays empty. The cSQL statement seems good. I have no errors, only the grid stays empty! Is there something I might be doing wrong?
Afier,
thisform.searchgrid.recordsourcetype = SQL would be before recordsource line. Here is testform :
* Testgrid is a copy of home()+"samples\data\orders"
* Important - all fields contained in SQL where are indexed 
* (to_name, order_amt & order_date)
* Create text1, text2, text3 with values "",0,{} on a test form
* Testform.init
cSQL = "select * "+;
"FROM testgrid INTO CURSOR myCursor "+;
"WHERE to_name = trim(thisform.text1.value) "+;
" and order_amt between "+;
"iif(empty(thisform.text2.value),0,thisform.text2.value) "+;
"and iif(empty(thisform.text2.value),999999,thisform.text2.value) "+;
" and order_date between "+;
"iif(empty(thisform.text3.value),{},thisform.text3.value) "+;
"and iif(empty(thisform.text3.value),date(),thisform.text3.value) "
thisform.searchgrid.recordsourcetype = 4
thisform.searchgrid.recordsource = cSQL
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform