Adodc1.RecordSource = "select sum(消费总金额) from data where 年='" & Text1.Text & "' and 月='" & Text2.Text & "' and 日='" & Text3.Text & "' and 消费人='" & Combo1.Text & "' and 消费地点='" & Combo2.Text & "'"上面代码所示
我使用了ADO控件和SQL语句
条件在TEXT1/TEXT2/TEXT3里我想知道如何在TEXT1(或TEXT2或TEXT3)里输入*时
代表条件为空如何实现
我使用了ADO控件和SQL语句
条件在TEXT1/TEXT2/TEXT3里我想知道如何在TEXT1(或TEXT2或TEXT3)里输入*时
代表条件为空如何实现
if text1.text<> "*" then
strsql = strsql & " and 年='" & Text1.Text & "'"
end if
if text2.text<>"*" then
strsql = strsql & " and 月='" & Text1.Text & "'"
end ifif text3.text<> "*" then
strsql = strsql & " and 日='" & Text1.Text & "'"
end ifstrsql = strsql & " and 消费人='" & Combo1.Text & "' and 消费地点='" & Combo2.Text & "'"
dim haswhere as booleanstrsql="select sum(消费总金额) from data "if text1<>"" then '注意,不要约定“*”代表空,多此一举。还不专业。
strsql=strsql & "where 年='" & text1 & "' "
haswhere=true
end ifif text2<>"" then
if haswhere then
strsql=strsql & "and 月='" & text2 & "' "
else
strsql=strsql & " where 月='" & text2 & "'"
end if
end ifif text3<>"" then 略另,你的表为什么建得这么烦琐?年月日还要分成三个字段呀?还用的是字符型?真想不通。
mysql="select sum(消费总金额) from data where 1=1"
if text1.value<>"*" then
mysql=mysql & "and 年='" & Text1.Text & "'"
end if
if text2.value<>"*"then
mysql=mysql & " and 月='" & Text2.Text & "'"
end if
if text3.value <>"*" then
mysql=mysql & " and 日='" & Text3.Text & "'"
end if
mysql=mysql & " and 消费人='" & Combo1.Text & "' and 消费地点='" & Combo2.Text & "'"
endif
Adodc1.RecordSource = mysql