- begin
- create table #table
- (
- theID int identity(1,1),
- PriceName varchar(1000),
- theDate datetime,
- Prices varchar(1000),
- theCTIDs varchar(500)
- )
- declare @MyDate datetime
- DECLARE mycursor CURSOR FOR--创建一个游标
- select distinct TicketDate from ConceTable where TicketID=5
- OPEN mycursor
- FETCH NEXT FROM mycursor
- INTO @MyDate
- WHILE @@FETCH_STATUS = 0
- BEGIN
- declare @Myid1 int,@thePriceNames varchar(1000),@thePrices varchar(5000),@theCTID varchar(2000)
- set @thePriceNames=''
- set @thePrices=''
- set @theCTID=''
- DECLARE mycursor1 CURSOR FOR--创建一个游标
- select CTID from dbo.ConceTable where TicketDate =@MyDate order by CTID
- OPEN mycursor1
- FETCH NEXT FROM mycursor1
- INTO @Myid1
- WHILE @@FETCH_STATUS = 0
- BEGIN
- declare @theConcessions varchar(100),@thePrice varchar(1000)
- select @theConcessions=Concessions from ConceTable where CTID =@Myid1
- set @thePriceNames = @thePriceNames +'|'+ @theConcessions
- --set @thePriceNames=@theConcessions
- select @thePrice=[TicketPrice] from ConceTable where CTID =@Myid1
- --set @thePrices = @thePrices+'|'+@thePrice
- set @theCTID=@theCTID+'|'+CONVERT(varchar(1000),@Myid1)
- set @thePrices= @thePrices+'|'+@thePrice
- --select @Myid1,@thePriceNames,@thePrices,@theConcessions,@thePrice
- FETCH NEXT FROM mycursor1
- INTO @Myid1
- END
- CLOSE mycursor1
- DEALLOCATE mycursor1
- insert into #table values(@thePriceNames,@MyDate,@thePrices,@theCTID)
- FETCH NEXT FROM mycursor
- INTO @MyDate
- END
- CLOSE mycursor
- DEALLOCATE mycursor
- select * from #table
- drop table #table
- end