Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagesql
titlePopulating nForm Lookups and Lookup Values from a Source Table
BEGIN

DECLARE @LOOKUP_ID UNIQUEIDENTIFIER;
DECLARE @USER_ID UNIQUEIDENTIFIER; 

SETSELECT @LOOKUP_ID=NEWID()
SELECT = NEWID()@USER_ID = PRINCIPAL_ID from NFORM.PRINCIPAL where LOGIN = 'MyLogin'; -- (should this be some sort of system login?)


INSERT INTO NFORM.LOOKUP
        ( LOOKUP_ID ,
          NAME ,
          CREATED_DATE ,
          CREATED_USER ,
          UPDATED_DATE ,
          UPDATED_USER ,
          IS_AVAILABLE_FOR_DROPDOWN
        )
SELECT @LOOKUP_ID , -- LOOKUP_ID - uniqueidentifier
          N'COLORSMyName' , -- NAME - nvarchar(255)
          GETDATE() , -- CREATED_DATE - datetime2
          1@USER_ID , -- CREATED_USER - uniqueidentifier
          GETDATE() , -- UPDATED_DATE - datetime2
          1@USER_ID , -- UPDATED_USER - uniqueidentifier
          1  -- IS_AVAILABLE_FOR_DROPDOWN - bit
          ;
 
INSERT INTO NFORM.LOOKUP_VALUE
        ( LOOKUP_VALUE_ID ,
          LOOKUP_ID ,
          NAME ,
          DESCRIPTION ,
          CREATED_DATE ,
          CREATED_USER ,
          UPDATED_DATE ,
          UPDATED_USER ,
         -- , IS_ACTIVE
        )
SELECT NEWID() , -- LOOKUP_VALUE_ID - uniqueidentifier
          @LOOKUP_ID , -- LOOKUP_ID - uniqueidentifier
          MySourceTable.NameCODE , -- NAME - nvarchar(600)
          MySourceTable.DescriptionDESCR , -- DESCRIPTION - nvarchar(600)
          GETDATE() , -- CREATED_DATE - datetime2
          1@USER_ID , -- CREATED_USER - uniqueidentifier
          GETDATE() , -- UPDATED_DATE - datetime2
          1@USER_ID , -- UPDATED_USER - uniqueidentifier
         -- , MySourceTable.IsActive1  -- IS_ACTIVE - bit
FROM MySourceTable;

END