Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Select query for dynamic search with if condition
Message
From
24/05/2004 12:45:43
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
24/05/2004 11:35:07
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00906123
Message ID:
00906577
Views:
17
>Cetin,
>
>I don't know how can that work:
>
>My requirement is:
>
>if i select just the project:
>
>it should be like this:
>
>select * from custmers where project = thisform.text1.value
>
>****
>if i select project and contract both then:
>the query should be:
>
>select * from customers where projcet = thisform.text1.value and contract=thisform.text2.value
>
>*******
>if i just select contract the query should be like this:
>
>
>select * from customers where contract = thisform.text2.value
>
>********
>
>Please let me know the one you have provided will it work that way.
>
>Thank you very much Cetin.

Raj,
That's effectively what you get with a single direct SQL.
set ansi off
select * from customers ;
  where project = trim(thisform.text1.value)and ;
      contract=trim(thisform.text2.value)
Suppose for text1 you type 'myProject', for text2 'myContract' or leave anyone of this as empty (no selection) :

if you type only the project then it's translated as :
select * from customers ;
  where project = 'myProject' and contract = '' 
if you type only the contract then it's translated as :
select * from customers ;
  where project = '' and contract = 'myContract' 
if you type both then it's translated as :
select * from customers ;
  where project = 'myProject' and contract = 'myContract' 
if you type none then it's translated as :
select * from customers ;
  where project = '' and contract = '' 
with ANSI OFF setting and = operator (not == operator) :

where Project = 'myProject' means :

Where Project STARTS WITH 'myProject'

where Project = '' means :

Where project starts with '' ( IOW whatever it's - all projects match).

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
Reply
Map
View

Click here to load this message in the networking platform