Home > database >  Data query
Data query

Time:09-24

More than control to query the database, the condition, to determine whether is empty, empty words in the query conditions, without it, there is not empty, write not to come out, which give an example

CodePudding user response:

What is the database

CodePudding user response:

Ms SQL

CodePudding user response:

Change your query, for example:
 
Select * from table
Where: (a=a or: a='ALL')
And (a: b=b or: a='ALL')
And (c or: c=c='ALL')


Under your control query, do judgment, for example:
 
String ls_a ls_b, ls_b
Ls_a=trim (sle_1. Text)
Ls_b=trim (sle_2. Text)
Ls_c=trim (ddlb_1. Text)

If isnull (ls_a) or ls_a="' then ls_a='ALL'
If isnull (ls_b) or ls_b="' then ls_b='ALL'
If isnull (ls_c) or ls_c="' then ls_c='ALL'

Dw_1. Retrieve (ls_a ls_b, ls_c)

CodePudding user response:

Change your query, for example:
 select * from table 
Where (a=: a or: a is null)
And (a: b=b or: b is null)
And (c or: c=c is null)


Under your control query, do judgment, for example:
 string ls_a ls_b, ls_b 
Ls_a=trim (sle_1. Text)
Ls_b=trim (sle_2. Text)
Ls_c=trim (ddlb_1. Text)

If isnull (ls_a) or ls_a="' then setnull (ls_a)
If isnull (ls_b) or ls_b="' then setnull (ls_b)
If isnull (ls_c) or ls_c="' then setnull (ls_c)

Dw_1. Retrieve (ls_a ls_b, ls_c)

CodePudding user response:

If is to query the same field where conditions IN retrieval, then array
String ls_args []
If the trim (sle_1. Text) & lt;> "' then
Ls_args [upperbound (ls_args) + +]=sle_1. Text
End the if
If the trim (sle_2. Text) & lt;> "' then
Ls_args [upperbound (ls_args) + +]=sle_2. Text
End the if
.
Dw_1. Retrieve (ls_args)

CodePudding user response:

Can use the like, if not empty is like '%' + '%' + variable
If air is directly like '%' %
  • Related