select
zwbh,zdbh,cmbh,cmmc,dwbh,cmdj,cmsl,xlbh,wdbz,
cmje,sjje,zkzt,fwzt,zdzt,zkl,xdh,
xsyh,skjh,fwyh,tcje,tmbj,kwbh,dcxh,dcbz,b.ryxm
from b_wdk
left join b_ryk b on b_wdk.fwyh=b.rybh
where zwbh=21
and zdbh=00002235
and cdbj='*'
order by xlbh,dcxh
有没有办法当cdbj的值有'*’的时候,只输出带*的数据,当cdbj都是空时就输出全部数据,cdbj值是动态的。
可以到网上搜索带有通配符 % -等,你的*是错误的符号
and (cdbj='*' and exists(select 1 from cbdj字段所在的表 where 条件 and cdbj='*'') or not exists(select 1 from cbdj字段所在的表 where 条件 and cdbj='*'') )
声明一个变量 代替cdbj。。。。。。。。。。。