Query result as attachment and mail

  • Hi expert

    I am using below code but did not getting emails from server,
    if I run only code upt to Subject then getting blank email but not getting with query,
    even if I run query in separate window then it gives me result but not run code as below and getting below error

    Msg 22050, Level 16, State 1, Line 0
    Error formatting query, probably invalid parameters
    Msg 14661, Level 16, State 1, Procedure sp_send_dbmail, Line 517
    Query execution failed: Msg 15404, Level 16, State 19, Server INSVLWS01, Line 1
    Could not obtain information about Windows NT group/user 'NETAFIM\ATULPA', error code 0x5.

    THE QUERY IS AS BELOW

    use CreditControl
    EXEC msdb.dbo.sp_send_dbmail
    @profile_name = 'SQL Mail',
    @recipients = 'atul.jadhav@netafim.com',
    @subject = 'Testing',
    @query = N'SELECT        LiveAR$.Account_No, LiveAR$.Branch_No, Customer_Master$.Name AS Account_Name, CustomerMaster_1.Name AS Branch_Name, Customer_Master$.Search, Customer_Master$.Final_District,
                             Region_Master$.State, Region_Master$.Reporting_State, DistrictWise_AreaManager$.Region, Region_Master$.SBU, Customer_Master$.Category, Customer_Master$.Main_Category,
                             SugarMillMaster$.SugarMillName, DistrictWise_AreaManager$.Manager, DistrictWise_AreaManager$.Region_Head, LiveAR$.Sales_Document, SalesOrder_Details$.Payment_Term,
                             Payment_Term$.PaymentTermDisc, SalesOrder_Details$.Purchase_Order, LiveAR$.Document_No, LiveAR$.Invoice_No, LiveAR$.Arrear, Agieng$.Bucket, Agieng$.ODFD AS [Overdue/Fall in due], LiveAR$.GL,
                             LiveAR$.Type, LiveAR$.Doc_Date, LiveAR$.Due_Date, LiveAR$.Amount, LiveAR$.PayT
    FROM            SalesOrder_Details$ RIGHT OUTER JOIN
                             LiveAR$ LEFT OUTER JOIN
                             SugarMillMaster$ ON LiveAR$.Account_No = SugarMillMaster$.PayerCode ON LiveAR$.Sales_Document = SalesOrder_Details$.SalesDocument LEFT OUTER JOIN
                             Agieng$ ON Agieng$.Days = LiveAR$.Arrear LEFT OUTER JOIN
                             CustomerMaster_1 ON LiveAR$.Branch_No = CustomerMaster_1.Customer LEFT OUTER JOIN
                             DistrictWise_AreaManager$ RIGHT OUTER JOIN
                             Customer_Master$ ON DistrictWise_AreaManager$.Final_District = Customer_Master$.Final_District LEFT OUTER JOIN
                             Region_Master$ ON Customer_Master$.RG = Region_Master$.RG ON LiveAR$.Account_No = Customer_Master$.Customer LEFT OUTER JOIN
                             Payment_Term$ ON SalesOrder_Details$.Payment_Term = Payment_Term$.Payment_Term
    WHERE        (DistrictWise_AreaManager$.Manager = N "Erravalli Project")
    ORDER BY LiveAR$.Account_No',
    @attach_query_result_as_file = 1,
    @query_attachment_filename = 'result.csv',
    @query_result_separator=',',
    @query_result_width =32767,
    @query_result_no_padding=1

Viewing 0 posts

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