BEGIN TRANSACTION;
DELETE FROM DC2.dbo.MS_100 WHERE PV_USER = '300';
COMMIT TRANSACTION;

BEGIN TRANSACTION;
INSERT INTO 
DC2.dbo.MS_100 (PV_USER
,PV1
,PV2
,PV3
,PV4
,PV5
,PV6
,PV7
,PV8
,PV_L1
,PV_L2
)
SELECT '300'
,CONVERT(VARCHAR(100),CASE WHEN T001.DEN_DATE=' ' OR T001.DEN_DATE IS NULL THEN ' ' ELSE SUBSTRING(T001.DEN_DATE,1,4)+'/'+SUBSTRING(T001.DEN_DATE,5,2)+'/'+SUBSTRING(T001.DEN_DATE,7,2) END),CONVERT(VARCHAR(100),FORMAT(T001.DEN_NO,'00000000')),CONVERT(VARCHAR(100),FORMAT(T001.DEN_GYO_NO,'##############0')),CONVERT(VARCHAR(100),RTRIM(T001.DEN_SYO_CD)),CONVERT(VARCHAR(100),RTRIM(T002.SYO_KANA)),CONVERT(VARCHAR(100),FORMAT(T001.TOTAL_QTY,'##############0.0')),CONVERT(VARCHAR(100),FORMAT(T001.URI_TAN,'##############0')),CONVERT(VARCHAR(100),FORMAT(T002.SHI_TANKA_YEN,'##############0.00')) ,
T001.DEN_DATE ,
RIGHT('00000000000000000000' + CAST(T001.DEN_NO AS VARCHAR),10)
FROM
DC2_DEMO.dbo.SAM_DENPYO T001
 LEFT OUTER JOIN DC2_DEMO.dbo.SAM_SYOHIN T002 ON
 T001.DEN_SYO_CD=T002.SYO_CD
WHERE
 T001.DEN_KB='2'
 AND T001.DEN_DATE BETWEEN '20100101' AND '20100103'
ORDER BY
  T001.DEN_DATE
 ,T001.DEN_NO
 ,T001.DEN_GYO_NO
;
COMMIT TRANSACTION;


