INSERT INTO TESISSEG.dbo.AS_CAMPOS
(CAMP_Nombre, CAMP_TipoDato, CAMP_Validaciones, CAMP_ColumnasDiseno, CAMP_Descripcion, EmpID)
SELECT 'material_sandwich', 'select', NULL, 4, 'Paneles sándwich', co.EmpID AS EmpID
FROM TESISSEG.dbo.Corredurias co;


INSERT INTO TESISSEG.dbo.AS_OPCIONESCAMPO
(OPC_Valor, OPC_Descripcion, EmpID)
SELECT 'Sí', 'Sí', co.EmpID AS EmpID
FROM TESISSEG.dbo.Corredurias co;

INSERT INTO TESISSEG.dbo.AS_OPCIONESCAMPO
(OPC_Valor, OPC_Descripcion, EmpID)
SELECT 'No', 'No', co.EmpID AS EmpID
FROM TESISSEG.dbo.Corredurias co;


INSERT INTO TESISSEG.dbo.AS_FORMCAMP
(FORM_Id, CAMP_Id, EmpID)
SELECT form.FORM_Id AS FORM_Id, (SELECT cmp.CAMP_Id FROM TESISSEG.dbo.AS_CAMPOS cmp WHERE cmp.EmpID = form.EmpID AND cmp.CAMP_Nombre = 'material_sandwich')  AS CAMP_Id, form.EmpID AS EmpID
FROM TESISSEG.dbo.AS_FORMS form
WHERE form.FORM_Nombre = 'Comercios y oficinas';




INSERT INTO TESISSEG.dbo.AS_OPCCAMP
(CAMP_Id, OPC_Id, EmpID)
SELECT
    camp.CAMP_Id,
    (
        SELECT
            TOP 1 opc.OPC_Id
        FROM
            TESISSEG.dbo.AS_OPCIONESCAMPO opc
        WHERE
                opc.EmpID = camp.EmpID
          AND opc.OPC_Descripcion = 'Sí'
        ORDER BY
            OPC_Id DESC) AS OPC_Id,
    camp.EmpID
FROM
    TESISSEG.dbo.AS_CAMPOS camp
WHERE camp.CAMP_Nombre = 'material_sandwich'


INSERT INTO TESISSEG.dbo.AS_OPCCAMP
(CAMP_Id, OPC_Id, EmpID)
SELECT
    camp.CAMP_Id,
    (
        SELECT
            TOP 1 opc.OPC_Id
        FROM
            TESISSEG.dbo.AS_OPCIONESCAMPO opc
        WHERE
                opc.EmpID = camp.EmpID
          AND opc.OPC_Descripcion = 'No'
        ORDER BY
            OPC_Id DESC) AS OPC_Id,
    camp.EmpID
FROM
    TESISSEG.dbo.AS_CAMPOS camp
WHERE camp.CAMP_Nombre = 'material_sandwich'