运行sql脚本时得到以下信息。讯息22050,第16级,状态1,第0行 初始化错误编号为-2147467259的sqlcmd库失败
当我删除Count语句和group by语句时,脚本将运行。
DECLARE @sub VARCHAR(100);
DECLARE @qry VARCHAR(1000);
DECLARE @msg VARCHAR(250);
DECLARE @query_ath NVARCHAR(1000);
DECLARE @query_attachment_filename NVARCHAR(1000);
DECLARE @tab char(1) = CHAR(9);
SELECT @sub = 'Daily Absence Report';
SELECT @msg = 'Please refer to the attached spread sheet for the
report.'
SELECT @query_ath = 'select dbserver.dbo.tabeA.some_field,
count(case dbserver.dbo.tabeA.field when a then 1
end) as count_1
from dbserver.dbo.tabeA
where a condition is met
group by dbserver.dbo.tabeA.some_field';
SELECT @query_attachment_filename = 'test.csv';
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'email',
@recipients = 'myemail@something.edu',
@body = @msg,
@subject = @sub,
@execute_query_database = 'dbserver',
@query = @query_ath,
@query_attachment_filename = 'ath_absences.csv',
@attach_query_result_as_file = 1,
@query_result_header = 1,
@query_result_width = 256,
@query_result_separator=@tab,
@quer`enter code here`y_result_no_padding = 1;
Msg 22050, Level 16, State 1, Line 0
Failed to initialize sqlcmd library with error number -2147467259.