use sybsystemprocs
go
checkpoint
go
set nocount on
go
print 'Generic stored procedure used by Sybase Job Scheduler Template jobs'
go
-- Remove the sp_jst_version_num if it exists before attempting to
-- create it
if exists( select 1 from sysobjects
           where name = 'sp_jst_version_num'
             and type = 'P'
             and (sysstat & 7) =4 )
    drop proc sp_jst_version_num
go
/*
** sp_jst_version_num
** Version: 1.0
**
** This stored procedure parses the @@version variable to get the
** version number and pass it back as an out variable.
**
** This stored procedure were developed as part of the ASE Job Scheduler
** templates provided by Sybase. It must be installed on the target
** ASE prior to running jobs created from Sybase templates that 
** specify its use.
**
** This stored proc is the called at job execution.  It is a support
** stored procedure and all values for it come from other stored
** procedures.
**
** Parameter definitions
** @version_num - the ASE version number taken from @@version
*/
create procedure sp_jst_version_num( @version_num varchar(32) out )
as
begin

    declare @version_txt varchar(128)
          , @short_version varchar(128)
          , @slash char(1)
          , @startNdx int
          , @endNdx int

    select @version_txt = @@version
         , @slash = '/'
    select @startNdx = charindex( @slash, @version_txt ) + 1
    select @short_version = substring( @version_txt, @startNdx, 10 )
    select @endNdx = charindex( @slash, @short_version )
    select @version_num = substring( @short_version, 1, @endNdx-1 )

    print 'sp_jst_version_num, version_num = %1!',  @version_num

    return 0
end
go
if exists( select 1 from sysobjects
           where name = 'sp_jst_version_num'
             and type = 'P'
             and (sysstat & 7) =4 )
begin
    print 'sp_jst_verion_num has been created'
    grant execute on sp_jst_version_num to public
end
go
