<pre>
use sybsystemprocs
go

if exists (select * from sysobjects where name = "sp_what" and type = 'P')
   drop proc sp_what
go

create procedure sp_what
@program varchar(16) = NULL     /* optional selective program specifier */
as

/* obtained off the Sybase-L list, 7/13/97
* Author: Saladin Elkadiki
* e-mail: elkadiki@cadvision.com
* www: www.cadvision.com/elkadiks  
*/

    /* If no program specified, list all the client connections */
    if (@program = NULL)
        select spid, program_name, hostname, blk=convert(char(3),blocked),
               dbname=substring(db_name(dbid),1,10), cmd
            from master..sysprocesses
            where hostname != ""
            order by hostname
    /* If "full" is specified, list both the clients and the SQL Server */
    else if (lower(@program) = "full")
        select spid, program_name, hostname, blk=convert(char(3),blocked),
               dbname=substring(db_name(dbid),1,10), cmd
            from master..sysprocesses
            order by hostname
    /* Otherwise, attempt a case-insensitive pattern match of the given */
    /* program name, e.g. "spool" matches "SPOOLER 1", "SPOOLER 2", etc. */ 
    else
        select spid, program_name, hostname, blk=convert(char(3),blocked),
               dbname=substring(db_name(dbid),1,10), cmd
            from master..sysprocesses
            where upper(program_name) like "%"+upper(@program)+"%"
            order by hostname
go

grant execute on sp_what to public
go
