I need help on writing a trigger in SQL Server to be used in Siebel:
The following statement generates the perfect key/row id:
select substring(replace (CAST (newid() as varchar(36)),'-',''),1,15)
I need help on writing a SQL Server 2005 trigger to generate this key.
Here is one way we did it. We setup OBIEE to generate a ROW_ID that is unique for the current load and hence why the WHERE clause can get the record to be updated.
IF EXISTS (SELECT name FROM sysobjects
WHERE name = 'S_CAMP_CON_Direct_Load_ROW_ID' AND type = 'TR')
DROP TRIGGER S_CAMP_CON_Direct_Load_ROW_ID
GO
CREATE TRIGGER S_CAMP_CON_Direct_Load_ROW_ID
ON S_CAMP_CON FOR INSERT
AS
UPDATE S_CAMP_CON
SET ROW_ID = (select substring(replace (CAST (newid() as varchar(36)),'-',''),1,15))
WHERE S_CAMP_CON.ROW_ID IN
(SELECT ROW_ID FROM inserted WHERE INSERT_CD = 'Direct Load')
But we are concerned by the uniqueness of ROW_ID since we are using a substring.