Some messages are not inserted

  • declare c1 cursor for select EmailID,CallerID,EmailDate,EmailTo,EmailFrom,Subject,MsgID,ProjectID from tblEmails order by EmailID

    declare @EmailID numeric

    declare @CallerID varchar(200)

    declare @EmailDate datetime

    declare @EmailTo varchar(250)

    declare @EmailFrom varchar(250)

    declare @Subject varchar(250)

    --declare @Notes varchar(5000)

    declare @MsgID varchar(250)

    declare @ProjectID numeric

    declare @uid numeric

    declare @pid numeric

    declare @direction tinyint

    declare @i int

    open c1

    FETCH NEXT FROM c1 into @EmailID,@CallerID,@EmailDate,@EmailTo,@EmailFrom,@Subject,@MsgID,@ProjectID

    -- Check @@FETCH_STATUS to see if there are any more rows to fetch.

    WHILE @@FETCH_STATUS = 0

    BEGIN

    set @uid = (select userid from users where uname=@CallerID)

    set @pid = (select projectid from [akorbi_beta].dbo.tbl_tblprojects_projects where TblProjectId=@ProjectID)

    set @direction=(select direction from emailBridge where oldmailID=@EmailID)

    print ''

    print 'EmailID : ' + cast(@EmailID as varchar(8))

    print 'CallerID : ' + @CallerID

    print 'UserId : ' + cast(@uid as varchar(8))

    print 'EmailDate : ' + cast(@EmailDate as varchar(20))

    print 'EmailTo : ' + @EmailTo

    print 'EmailFrom : ' + @EmailFrom

    print 'MsgID : ' + @MsgID

    print 'ProjectId : ' + cast(@ProjectID as varchar(6))

    print 'NewProjectId : ' + cast(@pid as varchar(6))

    print 'Direction : ' +cast(@direction as varchar(1))

    set @i=1

    declare @mid numeric

    insert into [Akorbi_beta].dbo.Messages(UserId,FromAddress,ToAddress,Subject,Direction,BodyText,BodyHtml,[Date],MsgID) select @uid,@EmailFrom,@EmailTo,@Subject,@direction,null,null,@EmailDate,@MsgID

    set @mid = (select @@identity)

    print 'MessageId : ' + cast(@mid as varchar(8))

    update [Akorbi_beta].dbo.Messages set [Akorbi_beta].dbo.messages.BodyHTML=tblEmails.Notes

    from tblEmails where tblEmails.EmailID=@EmailID and [Akorbi_beta].dbo.Messages.Messageid=@mid

    update [Akorbi_beta].dbo.Messages set [Akorbi_beta].dbo.messages.BodyText=tblEmails.Notes

    from tblEmails where tblEmails.EmailID=@EmailID and [Akorbi_beta].dbo.Messages.Messageid=@mid

    if(@pid is not null )

    begin

    insert into [Akorbi_beta].dbo.Messages_Tags(MessageId,ProjectId,TagType)values(@mid,@pid,1)

    --insert into [Akorbi_beta].dbo.tbl_Emails_Messages_Projects(EmailId,MessageId,ProjectId)values(@EmailID,@mid,@ProjectID)

    end

    FETCH NEXT FROM c1 into @EmailID,@CallerID,@EmailDate,@EmailTo,@EmailFrom,@Subject,@MsgID,@ProjectID

    END

    CLOSE c1

    DEALLOCATE c1

    go

  • On which insert does it fail?

    the first one or the insert after this statement (if(@pid is not null ))

    That's where I'd start looking if I were you.

    ALso do you have any error messages?

  • hi friend

    thanks for reply

    i got the solution

    where i was check the @pid is not null, that insert doesn,t work.

    now it's fine

    Thanks

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply