select * from tb where 年龄>(case when 员工类别='干部' then 60 else 性别='男' then 55 else 50 end)
declare @sqlstr nvarchar(1000) set @sql='select xxoo,ooxx from tbl where 1=1 ' if(@xxx<>'') begin set @sql=@sql+' and xxx='+@xxx end ... exe sp_execute (@sql)
不好意思,写错了! select * from tb where 年龄>(case when 员工类别='干部' then 60 else (case when 性别='男' then 55 else 50 end)end)
用IF写写试试if exists(select 1 from tb where 员工类别='干部') select * from tb where 年龄>60 if exists(select 1 from tb where 员工类别='工人') select * from tb where 年龄>(case when 性别='男' then 55 else 50 end)
declare @sqlstr nvarchar(1000)
set @sql='select xxoo,ooxx from tbl where 1=1 '
if(@xxx<>'')
begin
set @sql=@sql+' and xxx='+@xxx
end
...
exe sp_execute (@sql)
select * from tb where 年龄>(case when 员工类别='干部' then 60 else (case when 性别='男' then 55 else 50 end)end)
FilterDataSet(TSqlDataSet(dsbReport.DataSet),'.....');
dsbReport指向数据库中的员工信息表,
结果是想在页面的表格中只显示出符合要求的人员名单
select * from tb where 年龄>60
if exists(select 1 from tb where 员工类别='工人')
select * from tb where 年龄>(case when 性别='男' then 55 else 50 end)