I'm populating a table of about 15 columns from a table of about 1000 columns. I need to grab the time from the big table. That time is broken up into minutes and hours [rn-min] and [rn-hr] and I need them in an am/pm format in the new table. The table is populated by an outside company so I can't really change much about it, I did get them to put in a transferred column for me to check. It's big and slow and I only need a few columns and there is a lot of duplicate/similar rows. In any case I'm making the smaller table from the bigger table. I wrote a cursor, its slow and I was wondering if there was a better way to do it. I can't just use a simple insert(select columns) because I want to change the way the time and date are stored. Thanks, any help or advice is appreciated

```
declare data CURSOR READ_ONLY FORWARD_ONLY
for   
    select [raID],
            (otherfields),
            CAST([RA-rent-mm] as varchar(2)) + '/' + CAST([RA-rent-dd] as varchar(2)) + '/' +
            CAST([RA-Rent-CC] as varchar(2)) + CAST([RA-RENT-YY] as varchar(2)) [Date_Out],
            CAST([RA-Rtrn-mm] as varchar(2)) + '/' + CAST([RA-Rtrn-dd] as varchar(2)) +
            '/' + CAST([RA-Rtrn-CC] as varchar(2)) + CAST([RA-Rtrn-YY] as varchar(2)) [Date_In],
            CAST([RA-RENTAL-HOURS] as varchar(2)),
            CAST([RA-RENTAL-Minutes] as varchar(2)),
            CAST([RA-RTRN-HOURS] as varchar(2)),
            CAST([RA-RTRN-MINUTES] as varchar(2)),
            (other fields)
      from table_name
     where Transfered is null
       and [RA-rtrn-mm] != 0 --this keeps me from getting the duplicate/similar rows, once this doesn't equal 0 there aren't anymore rows so I just grab this one

declare @sql as varchar(max)
declare @raID int;
    (other fields),
declare @rentDate varchar(8);
declare @rtrnDate varchar(8);
declare @rentHours varchar(2);
declare @rentMinutes varchar(2);
declare @rtrnHours varchar(2);
declare @rtrnMinutes varchar(2);
    (other fields)

open data
    fetch next from data into 
        @raID,
        (other fields),
        @rentDate ,
        @rtrnDate ,
        @rentHours ,
        @rentMinutes ,
        @rtrnHours ,
        @rtrnMinutes ,
        (other fields),
    while @@FETCH_STATUS = 0
    begin
        set @rentMinutes = left('0' + @rentMinutes,2);--padding with 0 if minutes is 1-9
        set @rtrnMinutes = left('0' + @rtrnMinutes,2);

        --turning the varchar times into a time then back to varchar with correct am/pm notation
        declare @rentT time = @rentHours + ':' + @rentMinutes;
        declare @rtnT time = @rtrnHours + ':' + @rtrnMinutes;
        declare @rentTime varchar(7) = convert(varchar(15),@rentT, 100);
        declare @returnTime varchar(7) = convert(varchar(15),@rtnT, 100);

        --print @rentTime;
        set @sql = 'INSERT other_tbl_name(raID, (other fields), Date_Out, Date_In, Time_Out, Time_In,    (other fields))
                values ('+cast(@raID as varchar(max))+', (other fields),'''+@rentDate+''',
                            '''+@rtrnDate+''', '''+@rentTime+''', '''+@returnTime+''',
                            (other fields))';

        --exec(@sql)
        print @sql

        --need a way to make sure the insert worked before updating
        --need to update transferred to keep from updating the same info

        declare @update as varchar(max) = '
        UPDATE Capture.icokc_data
           SET Transfered = 1
         WHERE [raID] = '+cast(@raID as varchar(10))

        --exec(@update)
        --print @update

        fetch next from data into 
            @raID,
            (other fields)
            @rentDate ,
            @rtrnDate ,
            @rentHours ,
            @rentMinutes ,
            @rtrnHours ,
            @rtrnMinutes ,
            (other fields)
    end

close data;
deallocate data;

```