Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 simple control flow :S

Author  Topic 

mike123
Master Smack Fu Yak Hacker

1462 Posts

Posted - 2002-08-29 : 15:41:27
I need to modify this SP to check one more thing. I need to check if this statement:

SELECT count(userID) as total FROM tblhotList WHERE userid=@userID

is > 50

If its greater I would like to exit the SP, as I do with the IF EXISTS clause. If it is not greater I want to proceed with the insert.

What is the best way to implement this??




CREATE PROCEDURE [insert_HotList]

(
@UserID [int],
@HotUserID [int],
@Sort [tinyint]
--COULD SET OUTPUT PARAMETER TO RETURN WHAT HAPPENED
)
AS

SET NOCOUNT ON

IF Exists (SELECT userID FROM tbl_HotList WHERE userID = @UserID AND HotUserID = @HotUserID)

BEGIN
--SET @UserID = 0
Return
END

INSERT INTO [tbl_HotList]
( [UserID],
[HotUserID],
[Sort])

VALUES
( @UserID,
@HotUserID,
@Sort)

GO

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2002-08-29 : 19:53:39
How about
IF (SELECT count(userID) as total FROM tblhotList WHERE userid=@userID) > 50 BEGIN...

Go to Top of Page
   

- Advertisement -