我想使用Excel工作表中的查询将数据从SQL数据库填充到Excel工作表。数据出现在excel中,但列以奇怪的方式对齐。我只是想让列出现在与select查询相同的对齐方式中。
选择查询:
select
VVO.VV_CODE,
V.Vessel_name,
VVO.Arrival_date,
isnull(IGM.VIR_NO,'NULL') as VIR_NO,
isnull(VVO.TERMINAL_CODE,'NULL') as TERMINAL_CODE,
(SELECT
COUNT(BL_NO)
FROM
BL_DATA
WHERE
VV_CODE = VVO.VV_CODE AND
ISNULL(UNUSED_FLAG, '') <> '1') as TOTAL_INDEX,
(select CAST(COUNT(DISTINCT CONTAINER_NO) as int) from BL_Container where (Container_Size_Code = 19 or Container_Size_Code = 1) and BL_Container.VV_CODE = VVO.VV_CODE ) as TWENTY_FT,
(select CAST(COUNT(DISTINCT CONTAINER_NO) as int) from BL_Container where (Container_Size_Code = 20 or Container_Size_Code = 2) and BL_Container.VV_CODE = VVO.VV_CODE ) as FOURTY_FT,
(select CAST(COUNT(DISTINCT CONTAINER_NO) as int) from BL_Container where (Container_Size_Code = 3) and BL_Container.VV_CODE = VVO.VV_CODE ) as FOURTYFIVE_FT,
(select CAST(COUNT(DISTINCT CONTAINER_NO) as int) from BL_Container where (Container_Size_Code = 20 or Container_Size_Code = 19 or Container_Size_Code = 1 or Container_Size_Code = 2 or Container_Size_Code = 3) and BL_Container.VV_CODE = VVO.VV_CODE ) as Total_No_of_Cntrs,
(select((select CAST(COUNT(DISTINCT CONTAINER_NO) as float) from BL_Container where (Container_Size_Code = 19 or Container_Size_Code = 1) and BL_Container.VV_CODE = VVO.VV_CODE )/2 + (select CAST(COUNT(DISTINCT CONTAINER_NO) as float) from BL_Container where (Container_Size_Code = 20 or Container_Size_Code = 2) and BL_Container.VV_CODE = VVO.VV_CODE ) + (select CAST(COUNT(DISTINCT CONTAINER_NO) as float) from BL_Container where (Container_Size_Code = 3) and BL_Container.VV_CODE = VVO.VV_CODE ))) as Total_FFE
from Vessel_voyage VVO, Vessel V, IGM where V.Vessel_code = substring(VVO.VV_CODE,1,3) and VVO.VV_CODE = IGM.VV_CODE
excel表中填充的结果数据如下,