Passing a value from a stored procedure

  • I've created this procedure to count the number of times a particular condition was met in a log file.

    CREATE PROCEDURE SP_SMTPSTATS AS

    DECLARE @test-2 AS INT

    SELECT @test-2 = COUNT (*)

    FROM smtpstats

    Where clienthost = "10.0.0.64" AND Operation = "Data" AND bytesrecvd > 200 AND bytesrecvd < 2000

    ??????????????NOW WHAT????????????????????????????

    GO

    Now I need to finish the procedure to pass the value of @test-2 to a single text box in an Interdev asp page. The code may be all wrong, or I may be going about this all wrong I'm just looking for the right direction.

  • CREATE PROCEDURE SP_SMTPSTATS @RETCODE INT OUTPUT

    AS

    SELECT @RETCODE = COUNT (*)

    FROM smtpstats

    Where clienthost = "10.0.0.64" AND Operation = "Data" AND bytesrecvd > 200 AND

    bytesrecvd < 2000

    you can call this using the command object from Asp and read the @RETCODE variable , but you have to define this as a output variable from the calling script too .

    avoid using the sp_ prefix for your procedures as sql server would by default look up this proc in the master database

  • Another, really simple but effective way is return the variable as a record set. If your ASP's not too hot this is a doddle.

    CREATE PROCEDURE SP_SMTPSTATS AS

    DECLARE @test-2 AS INT

    SELECT @test-2 = COUNT (*)

    FROM smtpstats

    Where clienthost = "10.0.0.64" AND Operation = "Data" AND bytesrecvd > 200 AND bytesrecvd < 2000

    SELECT @test-2 AS Result

    Greg M Lucas
    "Your mind is like a parachute, it has to be open to work" - Frank Zappa

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

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