现在我的解决方案是使用UNION ALL
select OID_T025,F5_T025,F45_T025 from T_025 where OID_T025 in( select OID_T025 from T_025 where 'tag' in (select short_str from dbo.split(F45_T025,',')) union all
select OID_T025 from T_025 where '月消费2000' in (select short_str from dbo.split(F45_T025,',')))
其中dbo.split 是一个函数 也就是当你传入一个以逗号分割的字符串时它会帮你分割为表 比如我写 select * from dbo.split('123,2,4',',') 执行后 返回为
而我这样写的话在cs代码中处理就比表繁琐
string[] ts = cusName.Split(',');
if (ts.Length > 1)
{
filter.Append(" AND OID_T025 in (select OID_T025 from (");
for (int i = 0; i < ts.Length - 1; i++)
{
filter.Append("select OID_T025 from T_025 where '" + ts + "' in (select short_str from dbo.split(F45_T025,',')) union all ");
}
filter.Append("select OID_T025 from T_025 where '" + ts[ts.Length - 1] + "' in (select short_str from dbo.split(F45_T025,','))");
filter.Append(") as tb)");
}
1,可在后台数据库里,新建一个存储过程PR_F45_T025来解决该SQL语句;
2,CREATE OR REPLACE PROCEDURE SCOTT." PR_F45_T025 " ( )
as
begin
--只要包含 tag 和 月消费2000其中一个的标签全部显示
-- select OID_T025,F5_T025,F45_T025 from T_025 where OID_T025 in( select OID_T025 from T_025 where 'tag' in (select short_str from dbo.split(F45_T025,','))
-- union all
--select OID_T025 from T_025 where '月消费2000' in (select short_str from dbo.split(F45_T025,',')))
);
COMMIT;
end;