求注释
求高手注释下面句子,比较长,分数也会全给!因刚进,分数不多,望各牛人帮忙
还有中间的if 想用循环换掉,可尝试失败
USE [Financial-ODS-bk]
GO
/****** Object: StoredProcedure [dbo].[CrossTab] Script Date: 09/19/2012 16:29:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- CREATE procedure [dbo].[CrossTab]
CREATE procedure [dbo].[CrossTab]
(
@select varchar(2000),
@PivotCol varchar(100),
@Summaries varchar(100),
@GroupBy varchar(100),
@OtherCols varchar(100),
@OrderByCols varchar(100)
)
-- @OrderByCols varchar(100) = Null
AS
set nocount on
set ansi_warnings off
declare @sql varchar(1000)
Select @sql = ''
Select @OtherCols= isNull(', ' + @OtherCols,'')
create table #pivot_columns (pivot_column_name varchar(100))
Select @sql='select ''' + replace( + @PivotCol,',',''' as pivot_column_name union all select ''')+''''
insert into #pivot_columns
exec(@sql)
select @sql=''
create table #pivot_columns_data (pivot_column_name varchar(100),pivot_column_data varchar(100))
Select @PivotCol=''
Select @PivotCol=min(pivot_column_name) from #pivot_columns
While @PivotCol>''
Begin
insert into #pivot_columns_data(pivot_column_name,pivot_column_data)
exec
(
'select distinct ''' + @PivotCol +''' as pivot_column_name, convert(varchar(100),' + @PivotCol + ') as pivot_column_data from
('+
@select
+'
) T'
)
Select @PivotCol=min(pivot_column_name) from #pivot_columns where pivot_column_name>@PivotCol
end
if (select count(1) from #pivot_columns_data where pivot_column_data = '20120101') = 0
insert into #pivot_columns_data(pivot_column_name,pivot_column_data) values ('fromDateString', '20120101')
if (select count(1) from #pivot_columns_data where pivot_column_data = '20120201') = 0
insert into #pivot_columns_data(pivot_column_name,pivot_column_data) values ('fromDateString', '20120201')
if (select count(1) from #pivot_columns_data where pivot_column_data = '20120301') = 0
insert into #pivot_columns_data(pivot_column_name,pivot_column_data) values ('fromDateString', '20120301')
if (select count(1) from #pivot_columns_data where pivot_column_data = '20120401') = 0
insert into #pivot_columns_data(pivot_column_name,pivot_column_data) values ('fromDateString', '20120401')
if (select count(1) from #pivot_columns_data where pivot_column_data = '20120501') = 0
insert into #pivot_columns_data(pivot_column_name,pivot_column_data) values ('fromDateString', '20120501')
if (select count(1) from #pivot_columns_data where pivot_column_data = '20120601') = 0
insert into #pivot_columns_data(pivot_column_name,pivot_column_data) values ('fromDateString', '20120601')
if (select count(1) from #pivot_columns_data where pivot_column_data = '20120701') = 0
insert into #pivot_columns_data(pivot_column_name,pivot_column_data) values ('fromDateString', '20120701')
if (select count(1) from #pivot_columns_data where pivot_column_data = '20120801') = 0
insert into #pivot_columns_data(pivot_column_name,pivot_column_data) values ('fromDateString', '20120801')
if (select count(1) from #pivot_columns_data where pivot_column_data = '20120901') = 0
insert into #pivot_columns_data(pivot_column_name,pivot_column_data) values ('fromDateString', '20120901')
if (s