日期:2014-05-18  浏览次数:20555 次

如何实现根据不同类别和电话发送不同的邮件?
现有发邮件代码,但是他不能区分手机号的不同以及类别的不同,代码如下:
SQL code
    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)



如何修改能达到根据类别和电话的不同,会发送2封不同的邮件?

------解决方案--------------------
LZ能解释下不。
------解决方案--------------------
这是程序逻辑问题,慢慢分析.