UPDATE TBDD_MODULES SET PRODUCT_VERSION = '2.4.6.9' where NAME = 'Record-Organizer' 
GO

ALTER TABLE TBDD_USER_LOGIN_OUT
 ADD VERSION_CLIENT VARCHAR(30)
GO

ALTER TABLE TBDD_USER_MODULE_LOG_IN
 ADD VERSION_CLIENT VARCHAR(30)
GO
ALTER TRIGGER [dbo].[TBDD_USER_MODULE_LOG_IN_AFT_INS] ON [dbo].[TBDD_USER_MODULE_LOG_IN]
WITH EXECUTE AS CALLER
FOR INSERT
AS
BEGIN TRY
	DECLARE 
		@USER_ID		INTEGER,
		@MODULE			VARCHAR(50),
		@CLIENT_ID		INTEGER,
		@VERSION_CLIENT	VARCHAR(30)
	SELECT
  		@USER_ID = USER_ID,
		@MODULE = MODULE,
		@CLIENT_ID = CLIENT_ID,
		@VERSION_CLIENT = VERSION_CLIENT
	FROM INSERTED
	
	IF @VERSION_CLIENT IS NULL
		SET @VERSION_CLIENT = '1.0.0.0'
	INSERT INTO TBDD_USER_LOGIN_OUT (MODULE,USER_ID,CLIENT_ID,VERSION_CLIENT) VALUES (@MODULE,@USER_ID,@CLIENT_ID,@VERSION_CLIENT)
END TRY
BEGIN CATCH   
	PRINT 'FEHLER IN TRIGGER: ' + CONVERT(VARCHAR(30),ERROR_PROCEDURE()) + ' - ZEILE: ' + CONVERT(VARCHAR(10),ERROR_LINE())
	+ ' - FEHLER-MESSAGE: ' 
    + CONVERT(VARCHAR(500),ERROR_MESSAGE())
END CATCH
GO
CREATE VIEW VWDD_LOGIN_USER_HISTORY AS
SELECT	TOP (5000) 
	T.GUID, T.MODULE,T1.USERNAME, T1.NAME, T1.PRENAME, T1.GUID as USER_ID, T.CLIENT_ID,T2.CLIENT_NAME, T.LOGIN, T.LOGOUT, T.VERSION_CLIENT
FROM TBDD_USER_LOGIN_OUT T,
TBDD_USER T1,
TBDD_CLIENT T2
WHERE 
	T.USER_ID = T1.GUID 
	AND T.CLIENT_ID = T2.GUID
ORDER BY GUID DESC
GO
