<pre>
/* FileName: sp_convertprocs

   To Implement: isql -Usa -P < sp_convertprocs

   History: 22-Jan-96 v1.0 Creation [wg]

   Contains:
sp_convertpages
sp_convertmegs
sp_convertkbs
sp_convertblocks
sp_dropconverts
(used to contain sp_convertbytes??  Two references to it in uncorrected code)

*/

use sybsystemprocs
go

/* The sp_convertpages procedure starts here */

create proc sp_convertpages @num_pgs_in int as 

set nocount on
declare @total_byts_of_pgs int
declare @num_meg int
declare @num_blks int
declare @num_pages int
declare @num_kb int
declare @blockstring char(35)
declare @pagestring char(35)
declare @megstring char(35)
declare @kbstring char(35)
declare @bytstring char(35)

select @num_pages=@num_pgs_in
select @total_byts_of_pgs=(@num_pages * 2048)
select @num_blks=@total_byts_of_pgs/512
select @num_meg=@total_byts_of_pgs/1048576
/* where 1048576 is 1024*1024 bytes/meg) */

select @num_kb=@total_byts_of_pgs/1024

select @pagestring= "Total Pages Input     : " + convert(char(35),@num_pages)

select @blockstring="Number of Blocks      : " + convert(char(35),@num_blks)

select @megstring= "Number of Megabytes   : " + convert(char(35),@num_meg)

select @bytstring="Number of Bytes       : " + convert(char(35),@total_byts_of_pgs)

select @kbstring="Number of Kilobytes   : " + convert(char(35),@num_kb)

create table #space_convert_table(Storage_Conversion_Utility char(35))

insert #space_convert_table values (@pagestring)
insert #space_convert_table values ("--------------------------")
insert #space_convert_table values (@bytstring)
insert #space_convert_table values (@kbstring)
insert #space_convert_table values (@blockstring)
insert #space_convert_table values (@megstring)

select * from #space_convert_table
go

grant execute on sp_convertpages to public
go

/* The sp_convertmegs procedure starts here */

create proc sp_convertmegs @num_megs_in int as 

set nocount on
declare @total_byts_of_megs int
declare @num_megs int
declare @num_blks int
declare @num_pages int
declare @num_kb int
declare @blockstring char(35)
declare @pagestring char(35)
declare @megstring char(35)
declare @kbstring char(35)
declare @bytstring char(35)

select @num_megs=@num_megs_in
select @total_byts_of_megs=@num_megs * 1048576
/* where 1048576 is 1024*1024 bytes/meg) */

select @num_blks=@total_byts_of_megs/512
select @num_pages=@total_byts_of_megs/2048
select @num_kb=@total_byts_of_megs / 1024

select @megstring= "Total Megs Input    : " + convert(char(35),@num_megs)

select @pagestring="Number of Pages     : " + convert(char(35),@num_pages)

select @blockstring="Number of Blocks    : " + convert(char(35),@num_blks)

select @bytstring=  "Number of Bytes     : " + convert(char(35),@total_byts_of_megs)

select @kbstring= "Number of Kilobytes : " + convert(char(35),@num_kb)

create table #space_convert_table(Storage_Conversion_Utility char(35))

insert #space_convert_table values (@megstring)
insert #space_convert_table values ("--------------------------")
insert #space_convert_table values (@bytstring)
insert #space_convert_table values (@kbstring)
insert #space_convert_table values (@blockstring)
insert #space_convert_table values (@pagestring)

select * from #space_convert_table
go

grant execute on sp_convertmegs to public
go

/* The sp_convertkbs procedure starts here */

create proc sp_convertkbs @num_kb_in int as 

set nocount on
declare @total_byts_of_kb int
declare @num_megs int
declare @num_blks int
declare @num_pages int
declare @num_kb int
declare @blockstring char(35)
declare @pagestring char(35)
declare @megstring char(35)
declare @kbstring char(35)
declare @bytstring char(35)

select @num_kb=@num_kb_in

select @total_byts_of_kb=@num_kb * 1024

select @num_blks=@total_byts_of_kb/512

select @num_pages=@total_byts_of_kb/2048

select @num_megs=@num_kb/1024

select @megstring= "Number of Megs      : " + convert(char(35),@num_megs)

select @pagestring="Number of Pages     : " + convert(char(35),@num_pages)

select @blockstring="Number of Blocks    : " + convert(char(35),@num_blks)

select @bytstring=  "Number of Bytes     : " + convert(char(35),@total_byts_of_kb)

select @kbstring=   "Total Kilobytes     : " + convert(char(35),@num_kb)

create table #space_convert_table(Storage_Conversion_Utility char(35))

insert #space_convert_table values (@kbstring)
insert #space_convert_table values ("--------------------------")
insert #space_convert_table values (@bytstring)
insert #space_convert_table values (@megstring)
insert #space_convert_table values (@blockstring)
insert #space_convert_table values (@pagestring)

select * from #space_convert_table
go

grant execute on sp_convertkbs to public
go

/* The sp_convertblocks procedure starts here */

create proc sp_convertblocks @num_blks_in int as 

set nocount on
declare @total_byts_of_blks int
declare @num_meg int
declare @num_blks int
declare @num_pages int
declare @num_kb int
declare @blockstring char(35)
declare @pagestring char(35)
declare @megstring char(35)
declare @kbstring char(35)
declare @bytstring char(35)

select @num_blks=@num_blks_in

select @total_byts_of_blks=@num_blks * 512

select @num_pages=@num_blks/ 4

select @num_meg=@total_byts_of_blks/1048576 /* where 1048576 is 1024*1024 bytes/meg)*/

select @num_kb=@total_byts_of_blks / 1024

select @blockstring="Total Blocks Input   : " + convert(char(35),@num_blks)

select @pagestring= "Number of Pages      : " + convert(char(35),@num_pages)

select @megstring= "Number of Megabytes  : " + convert(char(35),@num_meg)

select @bytstring=  "Number of Bytes      : " + convert(char(35),@total_byts_of_blks)

select @kbstring=  "Number of KiloBytes  : " + convert(char(35),@num_kb)

create table #space_convert_table(Storage_Conversion_Utility char(35))

insert #space_convert_table values (@blockstring)
insert #space_convert_table values ("-----------------------------------")
insert #space_convert_table values (@bytstring)
insert #space_convert_table values (@kbstring)
insert #space_convert_table values (@megstring)
insert #space_convert_table values (@pagestring)

select * from #space_convert_table
go

grant execute on sp_convertblocks to public
go

/* 
Procedure to Drop Size Conversion Procedures

The sp_dropconverts stored procedure allows for the orderly drop of the size conversion procedures.

*/

create proc sp_dropconverts as

if exists (select * from sysobjects where name = "sp_convertpages")
        begin
                drop proc sp_convertpages
        end

if exists (select * from sysobjects where name = "sp_convertmegs")
        begin
                drop proc sp_convertmegs
        end

if exists (select * from sysobjects where name = "sp_convertkbs")

        begin
                drop proc sp_convertkbs
        end

if exists (select * from sysobjects where name = "sp_convertblocks")
        begin
                drop proc sp_convertblocks
        end
go

grant execute on sp_dropconverts to public
go
