while循环控制表的样式
2010-04-16 09:29
183 查看
select AwardID,t.TypeID,
DepartmentName,UserName,
UG_Name,T.AwardType,
T.AwardReason,convert(nvarchar(10),T.AwardTime,121) as 'AwardTime',T.Inactive
into #temp
from T_GLGZ_AwardInfo T
left join View_UserInfo v on t.userid= v.userid
where inactive = 0
declare @PrimaryIDTable table
(
AwardID int,
typeid nvarchar(10),
DepartmentName nvarchar(50),
UserName nvarchar(50),
UG_Name nvarchar(50),
AwardType nvarchar(50),
AwardReason nvarchar(100),
AwardTime nvarchar(50),
Inactive nvarchar(10)
)
--记录奖励类型
declare @typecount int
set @typecount = 0
while @typecount <=1
begin
--统计总条数
declare @count int
--记录总条数
declare @recount int
set @count = (select count(1) from T_GLGZ_AwardInfo where TypeID =@typecount)
set @recount = @count
WHILE @count >=0
BEGIN
if @recount = @count
begin
insert into @PrimaryIDTable
select top 1* from #temp where typeid = @typecount
end
else if @recount != 0 and @count = 0
begin
insert into @PrimaryIDTable
select '','合计',count(1),'','','','','','' from #temp where typeid = @typecount
end
else
begin
insert into @PrimaryIDTable
select AwardID,'',DepartmentName,UserName,UG_Name,AwardType,AwardReason,AwardTime,Inactive from #temp
where AwardID not in(select AwardID from @PrimaryIDTable) and typeid = @typecount
end
SET @count = @count - 1
END
SET @typecount = @typecount + 1
end
select AwardID,case typeid when '0' then '奖励' when '1' then '惩罚' when '合计' then '合计' end as 'TypeID',
DepartmentName,UserName,UG_Name,AwardType,AwardReason,AwardTime,Inactive
from @PrimaryIDTable
drop table #temp
DepartmentName,UserName,
UG_Name,T.AwardType,
T.AwardReason,convert(nvarchar(10),T.AwardTime,121) as 'AwardTime',T.Inactive
into #temp
from T_GLGZ_AwardInfo T
left join View_UserInfo v on t.userid= v.userid
where inactive = 0
declare @PrimaryIDTable table
(
AwardID int,
typeid nvarchar(10),
DepartmentName nvarchar(50),
UserName nvarchar(50),
UG_Name nvarchar(50),
AwardType nvarchar(50),
AwardReason nvarchar(100),
AwardTime nvarchar(50),
Inactive nvarchar(10)
)
--记录奖励类型
declare @typecount int
set @typecount = 0
while @typecount <=1
begin
--统计总条数
declare @count int
--记录总条数
declare @recount int
set @count = (select count(1) from T_GLGZ_AwardInfo where TypeID =@typecount)
set @recount = @count
WHILE @count >=0
BEGIN
if @recount = @count
begin
insert into @PrimaryIDTable
select top 1* from #temp where typeid = @typecount
end
else if @recount != 0 and @count = 0
begin
insert into @PrimaryIDTable
select '','合计',count(1),'','','','','','' from #temp where typeid = @typecount
end
else
begin
insert into @PrimaryIDTable
select AwardID,'',DepartmentName,UserName,UG_Name,AwardType,AwardReason,AwardTime,Inactive from #temp
where AwardID not in(select AwardID from @PrimaryIDTable) and typeid = @typecount
end
SET @count = @count - 1
END
SET @typecount = @typecount + 1
end
select AwardID,case typeid when '0' then '奖励' when '1' then '惩罚' when '合计' then '合计' end as 'TypeID',
DepartmentName,UserName,UG_Name,AwardType,AwardReason,AwardTime,Inactive
from @PrimaryIDTable
drop table #temp
相关文章推荐
- while循环语句 do-while循环语句 for语句嵌套循环语句辅助控制语句
- linux shell 流程控制(条件if,循环【for,while】,选择【case】语句实例
- 循环控制语句for while do-while if switch
- SHELLcase流程控制和for、while循环语句的使用
- Shell编程-流程控制-for、while和until循环
- 【DB.PL/SQL】程序流程控制 —— 循环 ——LOOP, END LOOP, WHILE, FOR, CONTINUE
- JAVA流程控制语句(顺序语句、判断、选择判断语句、while循环、do while循环、for循环、break、continue关键字)
- linux shell 流程控制(条件if,循环【for,while】,选择【case】语句实例
- Python第四天 流程控制 if else条件判断 for循环 while循环
- Java基础应用之循环控制(用while循环计算1+1/2!+1/3!…1/20!)
- 10,javase代码实战-循环控制——使用while与自增运算符实现遍历数组(一)
- Matlab编程与数据类型 -- 循环控制语句之二:while/end
- [bash]for、while/until、循环控制、循环输出定向和管接
- 6.15C循环控制语句for while
- Linux shell 流程控制(条件if,循环for,while)
- while(cin)循环的控制判断
- 流程控制语句:循环语句-while
- linux shell 流程控制(条件if,循环【for,while】,选择【case】语句实例
- linux shell 流程控制(条件if,循环【for,while】,选择【case】语句实例 --转载
- Linux shell 流程控制(条件if,循环for,while)