我试图在单列中获得100,000条记录,但仅获得160行。我正在使用它导出到csv。请帮助
declare @STR_EXPORT_CSV nvarchar(max);
SELECT @STR_EXPORT_CSV=STUFF(( SELECT '\r\n"'+f.UniqueId+'","'+ISNULL(f.LastName,'')+'","'+ISNULL(f.Firstname,'')+'","'+CONVERT(VARCHAR(20),ISNULL(f.Age,0))+'","'+
ISNULL(CONVERT(VARCHAR(10),CONVERT(DATE,f.birthdatetime),101) +' '+CONVERT(VARCHAR(5),CONVERT(TIME,f.birthdatetime),108),'')+'","'+
ISNULL(CONVERT(VARCHAR(10),CONVERT(DATE,f.death_datetime),101) +' '+CONVERT(VARCHAR(5),CONVERT(TIME,f.death_datetime),108),'')+'","'+
CONVERT(VARCHAR(20),ISNULL(f.genderName,''))+'","'+ISNULL(f.babyRefNo,'')+'","'+ISNULL(f.PresentAddress,'')+'","'+ISNULL(f.PermanentAddress,'')+'","'+ISNULL(f.vaccinationStatus,'')+'","'+ISNULL(S.Vacc_Desc,'')+'","'+ISNULL(CONVERT(VARCHAR(10),CONVERT(DATE,s.Schedule_Date),101),'')+'","'+ISNULL(CONVERT(VARCHAR(10),CONVERT(DATE,s.Actual_Date),101),'')+'","'+ISNULL(s.Vacc_Status,'')+'"' FROM ##FINAL_VACC_SCR_PATIENTS_EXPORT f
LEFT JOIN ##VACC_SCR_SAMPLE_CARD_DATA s on S.PatientId=f.patientId
order by RegionName asc, HospitalName asc, birthdatetime desc, uniqueId desc for xml path('')),1,4,'')
SELECT @STR_EXPORT_CSV;
答案 0 :(得分:0)
尝试至少在一个cast
中更改类型,您应明确地将其强制转换为varchar(max)
,
即使您的variable
被声明为varchar(max)
,但是从串联中得到的却是一个8000
个字符的字符串。
declare @s varchar(max);
set @s = replicate('a', 10000);
select len(@s) as len_;
--len_
---------
--8000
set @s = replicate(cast('a' as varchar(max)), 10000);
select len(@s) as len_;
--len_
--------
--10000