0

sp_send_dbmail を使用してテーブルから複数の電子メールを送信しようとしていますが、ストアド プロシージャを実行するとこのエラーが発生します。ここに私が得ているエラーがあります:

Parameter @attach_query_result_as_file cannot be 1 (true) when no value is specified for parameter @query. A query must be specified to attach the results of the query.

ここに私のコードがあります

  SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER proc [dbo].[myProc] as   
    declare rscursor cursor read_only
    for 
     select Email, FullName from myTable
      where userActive =1

        declare @Emails            nvarchar (100)
        declare @FullName  nvarchar (100)


    open rscursor
    fetch next from rscursor into @Emails, @FullName

    while @@fetch_status=0
        begin

             EXEC msdb.dbo.sp_send_dbmail
            @recipients = @Emails, 
            @subject = 'Sleep Diary Reminder',

            @body = 'this is just test',
            @profile_name = 'myProfile',


            @attach_query_result_as_file = 1        

        fetch next from rscursor into @Emails, @FullName

    end
    close rscursor
    deallocate rscursor

私のSPを実行しています

EXEC dbo.myProc
4

1 に答える 1

2

@queryプロシージャの変数を使用してクエリをメールに添付していないため、変数を完全にsp_send_dbmail設定または削除します。@attach_query_result_as_file = 0または、それがやりたい場合はクエリを添付します-追加@query = 'SELECT GETDATE()'してみて、それが機能することを確認できます。

于 2015-02-24T00:57:08.743 に答える