Thursday, February 10, 2011

Using @@ROWCOUNT to test data existance

-- test data existence like this...

SELECT 1 FROM Staff WHERE DivisionID = @DivisionId
IF (@@ROWCOUNT > 0)
-- Data found
BEGIN
RAISERROR('Cannot delete Division, it has staff',16,1)
END

DELETE Division WHERE @DivisionId = DivisionId

No comments: