Failed to initialize sqlcmd library with error number -2147467259 with a XML variable

725 Views Asked by At

I'm trying to send an email using sp_send_dbmail having my select coming from an XML variable, but I'm getting the following error:

Msg 22050, Level 16, State 1, Line 6
Failed to initialize sqlcmd library with error number -2147467259.

This is my query:

execute as login = 'user' 
EXEC msdb.dbo.sp_send_dbmail 
@profile_name = 'xpto', 
@Subject = 'Report', 
@recipients = '[email protected]',
@body_format = 'HTML',
@body = 'Test',
@attach_query_result_as_file = 1, 
@query_result_separator = ',',
@query_result_header = 0,
@query_result_no_padding = 1,
@query = 'SELECT @signal_xml = isnull(@ContentsFile,'')',
@query_attachment_filename = 'test.csv'

Is this possible? I'm trying to create a CSV file without the extra lines SSRS adds on the end of the files.

Thank you so much for you help! Any tip is pretty much appreciated!

0

There are 0 best solutions below