Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Select query for dynamic search with if condition
Message
From
22/05/2004 07:22:18
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
21/05/2004 15:21:34
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00906123
Message ID:
00906221
Views:
10
>I am trying to create a select query to search the table (dynamic search)
>if i fill the project and contract text boxes it should search with both criteria, if i dont fill project then it should ignore project and then search only with contract, if i fill only project then it should search only with project and ignore the contract if completely.
>the following i use in VB with multiple fields.
>
>I want to use the same style query in VFP.
>Can you please help me create it.
>
>******************
>ssql = "select * from projects"
>
>
>If combo1.Text <> "" Then
> wsql = " where proj = thisform.combo1.value"
>EndIf
>
>If combo2.Text <> "" Then
> If wsql <> "" Then
> wsql = wsql + " and " + " contract = thisform.combo2.value"
> Else
> wsql = " where contract = thisform.combo2.value"
> EndIf
>EndIf
>
>osql = " order by project_id into Cursor lcSource"
>
>ssql = ssql + wsql + osql
>
>&ssql
>
>************************
>Thank you very much in advance.

Raj,
You've created multiple threads for basically the same question. Your previous threads already have good replies. ie: As Sergey said you don't need to build complex looking strings and do a macro substitution, directly execute your query. Trying to create a string first only serve to make it more complex. Repeating here what Sergey already said :
set ansi off
select * from projects ;
  where proj = trim(thisform.combo1.value) ;
      and contract = trim(thisform.combo2.value) ;
  order by project_id into Cursor lcSource
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