我将查询结果从SQL导出到管道分隔文件。该文件需要一个标题和预告片记录,我将其合并到SQL代码中。我知道使用VS会更容易,但还没有时间学习这个程序。我从供应商那里收到一个错误,即拖车记录后存在空白行。有没有办法使用代码来防止这种情况?
set nocount on
select distinct
'HDR'
,'8.3'
,('00333_UHC_ASMP_DIRECT_'+ (convert (varchar (15), getdate(),112)) +'120000'+'.txt')
,'UHC'
,'DIRECT'
,'P'
,'Y'
,''
,'','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','',''
union all
select distinct
'DTL' as "SEG TYPE"
,pat.pat_last_name "Last Name"
,pat.pat_first_name "First Name"
,isnull(pat.PAT_MIDDLE_NAME, '') "MI"
,Convert(varchar(10),CONVERT(date,pat.BIRTH_DATE,106),101) DOB
,convert(varchar(9), sub.SUBSCR_NUM) "Member ID"
,'' as "SSN"
,(case when pat.SEX_C = '1' then 'F' when pat.sex_c = '2' then 'M' else 'U' end) GENDER
,'' as "STATE CODE"
,'' as "HIC"
,Convert(varchar(10),CONVERT(date,enc.CONTACT_DATE,106),101) FDOS
,Convert(varchar(10),CONVERT(date,enc.CONTACT_DATE,106),101) TDOS
,'' as "BILL TYPE"
,'' as "DISCHARGE"
,'' as "PROV ID"
,ser2.npi NPI
,'' as "PROV TYPE"
,'' as "FACILITY NM"
,nam.last_name "PROV LAST NAME"
,nam.first_name "PROV FIRST NAME"
,'' as "Specialty"
,'' as "TAX ID"
,enc.los_proc_code "CPT"
,'' as "REV CODE"
,'' as "SERVICE FDOS"
,'' as "SERVICE TDOS"
,'11' as "POS"
,'0' as "ICD INDIC"
,'' as "RA Code"
,'' as "Chart Barcode"
,'' as "Chart Enc Key"
,'' as "Chart DX Key"
,'' as "Contract ID"
,pat.ADD_LINE_1 "Mem Street Address"
,isnull(pat.ADD_LINE_2, '') "Mem Street Address 2"
,pat.city "Mem City"
,st.abbr "Mem State"
,pat.zip "Mem ZIP Code"
,'' as "CLAIMID/PCN"
,replace(convert(varchar, icd10.code), '.', '')
from pat_enc enc
left join patient pat on enc.pat_id = pat.pat_id
left join pat_enc_dx dx on enc.pat_enc_csn_id = dx.pat_enc_csn_id
left join clarity_ser ser on enc.visit_prov_id = ser.prov_id
left join clarity_ser_2 ser2 on ser.prov_id = ser2.prov_id
left join PAT_ACCT_CVG cov on pat.pat_id = cov.PAT_ID
left join coverage sub on cov.coverage_id = sub.coverage_id
left join V_COVERAGE_PAYOR_PLAN b on cov.coverage_id = b.coverage_id
left join cl_emp_ot emp on (ser.[user_id] = emp.[user_id] and (ser.prov_name = emp.USER_NAME_EXT_OT and ser.prov_name = 'STUART, JAMES G')) or (ser.[user_id] = emp.[user_id] and ser.prov_name <> 'STUART, JAMES G')
left join names_static nam on emp.EMP_NAME_RECORD_ID = nam.record_id
left join zc_state st on pat.state_c = st.state_c
left join zc_sex on pat.sex_c = zc_sex.RCPT_MEM_SEX_C
left join clarity_dep dep on ser2.PRIMARY_DEPT_ID = dep.department_id
left join V_EDG_HX_ICD10 icd10 on dx.dx_id = icd10.DX_ID
where b.benefit_plan_name = 'UNITED HEALTH SENIOR CARE' and enc.CONTACT_DATE between '2016-01-01' and '2016-12-31' and enc.los_proc_code is not null and dep.department_name like '%ripcpc%' and icd10.code is not null
/*order by pat.PAT_LAST_NAME, pat.PAT_FIRST_NAME, FDOS*/
UNION ALL
select distinct
'TRL'
,'00333'
,'25319'
,''
,''
,''
,''
,''
,'','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','',''
答案 0 :(得分:0)
如果您希望在拖车行之后空白行不使用Order by。如果你想删除它们尝试其他方式..
SELECT DISTINCT 1 AS SNO, ....... ETC
UNION ALL
SELECT DISTINCT 2 AS SNO, ....JOIN.... ETC
UNION ALL
SELECT DISTINCT 3 AS SNO, .... ETC
ORDER BY SNO