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 14:13:35
 
 
To
23/10/1998 12:30:47
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00149479
Message ID:
00149940
Views:
33
>>>>>>>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, could you check cursor contents? I mean just adding:
>>>>Select mycursor
>>>>Browse
>>>>At least, after this you will be aware what is wrong SELECT or Grid. If it's grid, you can always add few more lines:
>>>>Grid.Recordsource=""
>>>>Grid.Recordsource="mycursor"
>>>>Grid.Refresh
>>>
>>>I can not browse the cursor, because the SQL-command is not executed. It is still a string. The grid does not read the string I think.
>>
>>Ah, you use SQL-string as grid.recordsource? It's not the best way. Would you like to base you grid on cursor? Firstly, you select records into cursor, and then use this cursor as Grid.recordsource. It's more stable and easier to debug setting.
>
>Thank you for your answer. I'm now putting the result of the select-command into a cursor and everything is working now.
>
>The only thing that is not working is the following:
>In a textbox a user can enter a date. Now I want to use a select-command that gives only the record witch date is later then the date the user has entered. I have tried this: .... WHERE table.datefield > THISFORM.txtbox.VALUE.
>But that does not work. What am I doing wrong?

cWherestring="Table.Datefield>{"+DTOC(THISFORM.txtbox.VALUE)+"}"
Select * From ... ;
Where &cWherestring.
Edward Pikman
Independent Consultant
Previous
Reply
Map
View

Click here to load this message in the networking platform