日期:2014-05-16 浏览次数:20480 次
ALTER proc [dbo].[GetEditorStatisics]
(
@uid int
)
as
declare @sql varchar(800)
select @sql = isnull(@sql + '],[' , '') + Name from dbo.ArticleTypes group by dbo.ArticleTypes.Name
set @sql = '[' + @sql + ']'
set @sql='select editor,'+@sql+' from (select min(Name) as Type,MIN(Username) as editor,COUNT(*) as Count from ArticleTypes,Articles,Users where ArticleTypes.Id=Articles.TypeId and Users.Id=Articles.UID and (Users.Id='+CONVERT(varchar,@uid)+' or '+CONVERT(varchar,@uid)+'=0) group by Articles.TypeId) a pivot(max(Count) for Type in('+@sql+')) tbl'
exec @sql