| > SQL > SP 1 | |
/* Add a new user to the user table. All fields must be given except the ID
* (is generated automatically while storing). We create a log file entry also.
*
* Output: intSuccess = 0 if user already exists, else 1
*/
CREATE PROCEDURE pInsertUser
@strPCandUser nvarchar(255),
@intIDGruppe int,
@strBenutzer nvarchar(50),
@strKennwort nvarchar(50),
@strBeschreibung nvarchar(255),
@intStatus int,
@intSuccess int OUTPUT
AS
DECLARE @intAlreadyStoredCount int
SELECT @intAlreadyStoredCount = COUNT(*) FROM Benutzer WHERE Benutzer = @strBenutzer
IF @intAlreadyStoredCount > 0
BEGIN
INSERT INTO tblLog (DateStamp, UserName, ActionDone, val_int)
VALUES (GETDATE(), @strPCandUser, 'pInsertUser: User ' + @strBenutzer + ' already exists.', @intIDGruppe)
SET @intSuccess = 0
END
ELSE
BEGIN
INSERT INTO Benutzer (IDGruppe, Benutzer, Kennwort, Beschreibung, Status)
VALUES (@intIDGruppe, @strBenutzer, @strKennwort, @strBeschreibung, @intStatus)
INSERT INTO tblLog (DateStamp, UserName, ActionDone, val_int)
VALUES (GETDATE(), @strPCandUser, 'pInsertUser: User ' + @strBenutzer + ' inserted.', @intIDGruppe)
SET @intSuccess = 1
END
GO