34,874
社区成员
发帖
与我相关
我的任务
分享ALTER proc [dbo].[存储过程]
(
参数 varchar(20),
参数 varchar(20),
参数 int
)
as
SET NOCOUNT ON
select * from (
select 1 as 字段,'字段' as 字段,count(a.字段) as 字段
from 表 a
left join 表 b on a.字段 = b.字段
left join 表 c on b.字段=c.字段 and c.字段=0
left join 表 d on b.字段=d.字段 and d.字段=0
where a.字段 like 'YF%' and b.字段=0 and (a.字段 is null or a.字段=2) and isnull(b.字段,0)<>1
and b.字段=1 and a.字段=b.字段
and a.字段=参数 and a.字段=参数
and exists (select 1 from 视图 pw where 视图字段=参数 and 视图字段=c.字段 and (字段 is null or 字段=d.字段) and (字段 is null or 字段=b.字段))
union
select 1 as 字段,'字段' as 字段,count(a.字段) as 字段
from 表 a
left join 表 b on a.字段 = b.字段
left join 表 c on b.字段=c.字段 and c.字段=0
left join 表 d on b.字段=d.字段 and d.字段=0
where a.字段 like 'YF%' and b.字段=0 and (a.字段 is null or a.字段=2) and isnull(b.字段,0)<>1
and b.字段=1 and a.字段=b.字段
and a.字段=参数 and a.字段=参数
and exists (select 1 from 视图 pw where 视图字段=参数 and 视图字段=c.字段 and (字段 is null or 字段=d.字段) and (字段 is null or 字段=b.字段))
union
select 1 as 字段,'字段' as 字段,count(a.字段) as 字段
from 表 a
left join 表 b on a.字段 = b.字段
left join 表 c on b.字段=c.字段 and c.字段=0
left join 表 d on b.字段=d.字段 and d.字段=0
where a.字段 like 'YF%' and b.字段=0 and (a.字段 is null or a.字段=2) and isnull(b.字段,0)<>1
and b.字段=1 and a.字段=b.字段
and a.字段=参数 and a.字段=参数
and exists (select 1 from 视图 pw where 视图字段=参数 and 视图字段=c.字段 and (字段 is null or 字段=d.字段) and (字段 is null or 字段=b.字段))
) c
order by iid