Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SProc (T-SQL) OUT question
Message
 
À
18/04/2007 15:28:07
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2000
Divers
Thread ID:
01217449
Message ID:
01217460
Vues:
8
This message has been marked as the solution to the initial question of the thread.
Something like this:
ALTER PROCEDURE dbo.sp_InProgress 
(
   @action char(5) = 'QUERY',
   @UserId char(10) = NULL OUTPUT,
   @CurrentDate datetime = NULL output
)
AS
SET NOCOUNT ON
IF @action NOT IN ('START','STOP','QUERY') SET @action = 'QUERY';
IF @action = 'START'
BEGIN
   IF EXISTS (SELECT InProgress FROM setup)
   BEGIN
      UPDATE setup
      SET inprogress = 1, datetime = getDate(), who = @UserId
   END
   ELSE
   BEGIN
      INSERT INTO setup (datetime, inprogress, who) VALUES (getDate(), 1, @UserId)
   END
END
ELSE
IF @action = 'STOP'
BEGIN
   IF @UserId IS NULL
   BEGIN
      UPDATE setup
      SET inprogress = 0, datetime = getDate()
   END
ELSE
   BEGIN
      UPDATE setup
      SET inprogress = 0, datetime = getDate(), who = @UserId
   END
END
ELSE
    -- 'QUERY'
    DECLARE @cUserWhoStartedIt char(10)
    SELECT @cUserWhoStartedIt = who FROM setup 
    SET  @CurrentDate = GETDATE()
    --- do what you want to do in the query
    SET @UserId = @cUserWhoStartedIt

BEGIN
   SELECT * FROM setup
END
The you could try it in QA (or SSMS):
DECLARE @lcUserId char(10)
DECLARE @ldCDate DateTime

EXEC sp_InProgress @UserId = @lcUserId OUTPUT, @CurrentDate = @ldCDate OUTPUT
SELECT @lcUserId, @ldCDate
(not tested)
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform