• Yes, if the table already exists then add an INSERT INTO command below the CTE declaration above the SELECT.

    If the table doesnt exist, add the INTO clause above the FROM.

    WITH rows AS (SELECT *, row_number() OVER (ORDER BY emppin, trxdate) AS rownum

    FROM rawtrx)

    INSERT INTO atable (col1, col2,.................)

    SELECT *, rowsMinusOne.trxtime AS trxtimeIN, ISNULL(rows.trxtime, 1) AS trxtimeOUT

    FROM rows AS rowsMinusOne LEFT OUTER JOIN

    rows ON rows.rownum = rowsMinusOne.rownum + 1 AND rows.emppin

    WITH rows AS (SELECT *, row_number() OVER (ORDER BY emppin, trxdate) AS rownum

    FROM rawtrx)

    SELECT *, rowsMinusOne.trxtime AS trxtimeIN, ISNULL(rows.trxtime, 1) AS trxtimeOUT

    INTO atable

    FROM rows AS rowsMinusOne LEFT OUTER JOIN

    rows ON rows.rownum = rowsMinusOne.rownum + 1 AND rows.emppin