declare @dyid Varchar(50),@code Varchar(50),@name Varchar(50),@ottime Varchar(50),@lineid Varchar(50),@linename Varchar(50)
declare @TempTable table(autoid int identity,ID varchar(50),IDR varchar(50),COST Varchar(50),PAYID varchar(50),PAYAMOUNT Varchar(50),REMAIN Varchar(50))
declare @i int
set @i = 0
declare A Cursor for
select dyid,code,name,ottime,lineid,linename from daily_report_detail where dyid=1
open A
FETCH NEXT FROM A INTO @dyid,@code,@name,@ottime,@lineid,@linename
WHILE @@FETCH_STATUS =0
begin
set @i = @i +1
insert into @TempTable(ID,IDR,COST,PAYID,PAYAMOUNT,REMAIN) values(case when @i = 1 then @dyid else '' end,@code,@name,@ottime,@lineid,@linename)
FETCH NEXT FROM A INTO @dyid,@code,@name,@ottime,@lineid,@linename
end
CLOSE A
DEALLOCATE A
select ID,IDR,COST,PAYID,PAYAMOUNT,REMAIN from @TempTable