Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SProc (T-SQL) OUT question
Message
 
To
18/04/2007 15:28:07
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01217449
Message ID:
01217460
Views:
9
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.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform