CREATE proc [dbo].[usp_manyidu]
(
@seatno nvarchar(30),
@pageIndex int,
@pageSize int,
@rsCount int out
)
as
begin
declare @sql nvarchar(max) --拼接内核SQL
declare @where nvarchar(max)=' where 1=1' --查询条件拼接字符串
declare @cols nvarchar(max) --查询字段、计算字段
declare @sort nvarchar(50) --排序
set @sql=' from dbo.log where seatno is not null and seatno<>'''' group by seatno '
set @cols='seatno,SUM(case when manyidu=0 then 1 else 0 end) as manyi,
SUM(case when manyidu=1 then 1 else 0 end) as yiban,
SUM(case when manyidu=2 then 1 else 0 end) as bumanyi,
SUM(case when manyidu IS null or manyidu='''' then 1 else 0 end) as weipingjia'
set @sort='order by seatno'
if(@seatno <>'')
set @where+=' and seatno='+@seatno
declare @strSQL nvarchar(max)
set @strSQL=N'select * from (select ROW_NUMBER() over('+@sort+') as tmpid,* from( select * from (select '+@cols+@sql+') as tmpTable1'+@where+') as tmpTable2) as tmpTable3'
+' where tmpid between '+STR((@pageIndex-1)*@pageSize+1)+' and '+STR(@pageIndex*@pageSize)
print @strSQL
exec(@strSQL)
set @strSQL='select @total=count(*) from (select '+@cols+@sql+') as tmpTable'+@where
print @strSQL
exec sp_executesql @strSQL,N'@total int out',@total=@rsCount out
end
GO
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有