日期:2014-05-18 浏览次数:20555 次
CREATE TABLE [dbo].[SMSCache] ( [ID] [int] IDENTITY (1, 1) NOT NULL , [PlantName] [varchar] (20) NULL , [BussType] [varchar] (20) NULL , [MobileTel] [varchar] (15) NULL , [Content] [varchar] (255) NULL , [Status] [smallint] NOT NULL , [SendTime] [datetime] NULL ) ON [PRIMARY] GO CREATE TABLE [dbo].[SMSMail] ( [ID] [int] IDENTITY (1, 1) NOT NULL , [Subject] [varchar] (20) NULL , [Mail] [varchar] (255) NULL , [Content] [varchar] (2000) NULL , [Status] [smallint] NOT NULL , [SendTime] [datetime] NULL ) ON [PRIMARY] GO select PlantName,BussType,MobileTel,MAX(ID) MaxID into #tmpCache from SMSCache where Status=1 group by PlantName,BussType,MobileTel declare @Mail varchar(200), @Subject varchar(50), @content varchar(200), @total_content varchar(2000) declare @Ordinal int declare cur INSENSITIVE cursor for select a.MobileTel as Mail,'[' + a.PlantName + ']' + a.BussType as Subject,b.Content from #tmpCache a inner join SMSCache b on a.PlantName=b.PlantName and a.BussType=b.BussType and a.MobileTel=b.MobileTel and a.MaxID>=b.ID open cur fetch next from cur into @Mail, @Subject, @Content while (@@FETCH_STATUS = 0) begin if (@total_content is null) begin set @Ordinal = 1 set @total_content = cast(@Ordinal as varchar) + '. ' + @content end else begin set @Ordinal = @Ordinal + 1 set @total_content = @total_content + char(10) + char(13) + cast(@Ordinal as varchar) + '. ' + @content end print (@Mail + ', ' + @Subject + ', ' + @Content) fetch next from cur into @Mail, @Subject, @Content end close cur deallocate cur print (cast(@Ordinal as varchar) + '行未读信息:' + char(10) + char(13) + @total_content)