@procname varchar(28) = NULL, -- name to use when making the
-- task and the wrapper/condenser
-- stored procs
@maketask bit = 1 -- make a task? or just make the
-- stored procs?
as
begin
declare @rc int
declare @taskname varchar(24)
declare @yearchar varchar(2)
declare @monthchar varchar(2)
declare @daychar varchar(2)
declare @hourchar varchar(2)
declare @minchar varchar(2)
declare @secchar varchar(2)
declare @currdate datetime
declare @freqtype_ int
declare @freqinterval_ int
declare @freqsubtype_ int
declare @freqsubinterval_ int
declare @freqrelativeinterval_ int
declare @freqrecurrencefactor_ int
declare @activestartdate_ int
declare @activestarttimeofday_ int
declare @complete varchar(255)
declare @buf varchar(255)
declare @taskid int
declare @suid smallint
declare @myusername varchar(30)
declare @sspid varchar(20)
declare @i tinyint
declare @j tinyint
declare @c char(1)
declare @newquery1 varchar(255)
declare @newquery2 varchar(255)
declare @newquery3 varchar(255)
declare @newquery4 varchar(255)
declare @ch_fixedfont char(1)
declare @ch_bolditalic char(1)
declare @ch_colheaders char(1)
declare @ch_lastupdated char(1)
declare @ch_HTMLheader char(1)
-- check args
if ((@fixedfont <> 0) and (@fixedfont <> 1))
begin
RAISERROR(16947,11,0)
return (1)
end
if ((@bold <> 0) and (@bold <> 1))
begin
RAISERROR(16948,11,0)
return (2)
end
if ((@italic <> 0) and (@italic <> 1))
begin
RAISERROR(16949,11,0)
return (3)
end
if ((@colheaders <> 0) and (@colheaders <> 1))
begin
RAISERROR(16950,11,0)
return (4)
end
if ((@lastupdated <> 0) and (@lastupdated <> 1))
begin
RAISERROR(16951,11,0)
return (5)
end
if ((@HTMLheader < 1) or (@HTMLheader > 6))
begin
RAISERROR(16952,11,0)
return (6)
end
select @rc = 0
exec @rc = sp_validname @username_
if (@rc = 1)
begin
RAISERROR(16954,11,0)
return (8)
end
if (@dbname != NULL)
if (not(exists(select * from master..sysdatabases where name = @dbname)))
begin
RAISERROR(16955,11,0)
return (9)
end
if ((@whentype < 1) or (@whentype > 4))
begin
RAISERROR(16956,11,0)
return (10)
end
if ((@unittype < 1) or (@unittype > 3))
begin
RAISERROR(16957,11,0)
return (11)
end
if ((@whentype = 2) and (@targetdate < 19000101))
begin
RAISERROR(16958,11,0)
return (12)
end
if (((@whentype = 2) or (@whentype = 3)) and (@targettime = -1))
begin
RAISERROR(16959,11,0)
return (13)
end
if ((@whentype = 3) and (@dayflags = 0))
begin
RAISERROR(16960,11,0)
return (14)
end
if ((@whentype = 3) and (@numunits < 1))
begin
RAISERROR(16961,11,0)
return (15)
end
if ((@whentype = 4) and (@numunits < 1))
begin
RAISERROR(16962,11,0)
return (16)
end
if ((@whentype = 4) and ((@unittype < 1) or (@unittype > 3)))
begin
RAISERROR(16963,11,0)
return (17)
end
if ( ((@URL = '?') and (@reftext <> '?')) or
((@URL <> '?') and (@reftext = '?')) or
((@table_urls = 1) and (@url_query is null)) or
((@table_urls = 0) and (@url_query is not null)) )
begin
RAISERROR(16964,11,0)
return (18)
end
-- override the @username_ value if suid != 1 (sa)
-- if @dbname is NULL, supply a default
select @suid = suid from master..sysprocesses where spid = @@spid
if ((@suid != 1) or (@dbname = NULL))
begin
select @sspid = convert(varchar(20),@@spid)
select @dbname = d.name from
master..sysdatabases d, master..sysprocesses p
where d.dbid = p.dbid
and spid = @@spid
exec("insert into msdb..MSWork (spid,value1) select @@spid, name from "+@dbname+"..sysusers u, master..sysprocesses p where u.uid = p.uid and spid = "+@sspid)
if (@suid != 1)
select @username_ = convert(varchar(30),value1) from msdb..MSWork
exec("CREATE PROCEDURE "+@procname+" WITH ENCRYPTION AS "+@newquery1+@newquery2+@newquery3+@newquery4)
if (not exists (select 1 from sysobjects where type = 'P' and name = @procname)) return(26)
exec("CREATE PROCEDURE "+@procname+";2 WITH ENCRYPTION AS exec master..xp_cmdshell 'mssqlwpw "+@username_+"!"+@dbname+"!"+@ch_fixedfont+@ch_bolditalic+@ch_colheaders+@ch_lastupdated+@ch_HTMLheader+"0!"+@templatefile+"!"+@webpagetitle+