HELP Needed - Stored Proc accepting Input Variable!

  • This silly program ran with 'exec usp_monitorproc 57' never goes into the IF statements though the parameter I am passing is numberic...HELP! Do you know what I am doing wrong?

    SET QUOTED_IDENTIFIER ON

    GO

    SET ANSI_NULLS ON

    GO

    CREATE  PROCEDURE dbo.usp_monitorproc

    (@SPID int) AS

    /***************************************************************************

    ****          Purpose:  show processes                                           ****

    **** Aug 2004              Anna Keller          Over Lay OCC     ****

    ***************************************************************************/

    -- ---------------------------------------------------------------

    -- Declare variables

    -- ---------------------------------------------------------------

    Declare @End_Of_Process char(1)

    Begin Tran

    -- select @End_Of_Process = 'N'

    -- While (@End_Of_Process = 'N')

    print 'SPID:['+cast(@SPID as char(6))+']'

      If not isnumeric(@SPID)

         Begin

     PRINT 'Select all'

            select SPID, KPID, cpu, physical_io, cmd, nt_username, memusage, WAITTIME, LASTWAITTYPE, hostname, program_name, login_time,open_tran, status from sysprocesses

         End

      If  isnumeric(@SPID)

         Begin

     PRINT 'Select 1 SPID'

            select SPID, KPID, cpu, physical_io, cmd, nt_username, memusage, WAITTIME, LASTWAITTYPE, hostname, program_name, login_time,open_tran, status from sysprocesses where SPID = @SPID

         END

    Return(0)

    GO

    SET QUOTED_IDENTIFIER OFF

    GO

    SET ANSI_NULLS ON

    GO

  • You could try the following

    ISNUMERIC returns an integer so...

      If isnumeric(@SPID) = 1

         Begin

     PRINT 'Select all'

            select SPID, KPID, cpu, physical_io, cmd, nt_username, memusage, WAITTIME, LASTWAITTYPE, hostname, program_name, login_time,open_tran, status from sysprocesses

         End

      If  isnumeric(@SPID) = 0

     

    Regards..Graeme

  • try

     

    If Select ( isnumeric(@SPID)  ) = 0

         Begin

     PRINT 'Select all'

            select SPID, KPID, cpu, physical_io, cmd, nt_username, memusage, WAITTIME, LASTWAITTYPE, hostname, program_name, login_time,open_tran, status from sysprocesses

         End

    If Select ( isnumeric(@SPID)  ) = 1

         Begin

     PRINT 'Select 1 SPID'

            select SPID, KPID, cpu, physical_io, cmd, nt_username, memusage, WAITTIME, LASTWAITTYPE, hostname, program_name, login_time,open_tran, status from sysprocesses where SPID = @SPID

         END

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply