您的位置:首页 > Web前端 > CSS

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: