vini
Starting Member
11 Posts |
Posted - 2006-11-30 : 08:47:13
|
Hiya all,I am trying to export from a header and a detail table to a textfile with the following format,HEADER 1 DETAIL 1 DETAIL 1 DETAIL 1HEADER 2 DETAIL 2 DETAIL 2 DETAIL 2etcetcEDIT: I Include the sql if it helpsSELECT --HEADER'HHF' AS Field1,'0000000000' AS SerialNo,'1' AS TransStatus,W.WH_Code,(CASE WHEN DT.DType_Code = 'U' OR DT.DType_Code = 'L' THEN DT.DType_Code ELSE '' END) AS ToStoreCode,'1' AS DocSubType,'' AS AccountCode,(DT.DType_Code + S.SM_Code + RIGHT(D.DOC_Code,6)) AS DOC_Reference,(SELECT SUBSTRING(CONVERT(varchar,D.DOC_date,120),9,2) + SUBSTRING(CONVERT(varchar,D.DOC_date,120),6,2) + SUBSTRING(CONVERT(varchar,D.DOC_date,120),1,4)) AS DOC_Date,(CASE WHEN DT.DType_Code = 'SI' OR DT.DType_Code = 'SH' OR DT.DType_Code = 'SF' OR DT.DType_Code = 'SC' OR DT.DType_Code = 'TT' OR DT.DType_Code = 'TF' OR DT.DType_Code = 'AD' OR DT.DType_Code = 'JI' THEN DT.DType_Code ELSE '' END) AS DocumentType,'' AS PriceCode,D.DOC_CashFlag AS CashWeeklyFlag,D.DOC_PaidFlag AS CashPaidFlag,(SELECT SUBSTRING(CONVERT(varchar,getdate(),120),9,2) + SUBSTRING(CONVERT(varchar,getdate(),120),6,2) + SUBSTRING(CONVERT(varchar,getdate(),120),1,4)) AS REF_DateFROM tblDocuments AS D INNER JOIN tblWarehouse AS W ON D.DOC_WhId = W.WH_Id INNER JOIN tblDocumentsTypes AS DT ON D.DOC_TypeId = DT.DTYPE_Id INNER JOIN tblSalesman AS S ON D.DOC_SmId = S.SM_Id SELECT --DETAIL'HHL' AS Field1,'0000000000' AS SerialNo,PROD_Code AS ItemCode,DTL_ProdQuantity AS ItemQty,DTL_ProdAmount AS ItemGrossValue,DTL_ProdDiscAmount AS ItemDiscAmount,'0000000.00' AS ItemOverallDisc,DTL_ProdVatAmount AS ItemVatValue,'0000000.00' AS ItemDiscVatVal,PVT_Code AS ItemVatCode,(DTL_ProdAmount - DTL_ProdDiscAmount) AS ItemSalePrice,DTL_DiscPerc0 AS ItemDiscRate,'xxxxxx' AS ItemVatRate,DTL_ProdUnitPrice AS ItemUnitPriceFROM tblDocumentDetails INNER JOIN tblProducts ON DTL_ProdId=PROD_IdINNER JOIN tblPvatTypes ON PROD_PvtId = PVT_IdAnyone got any ideas?Thanks in advance,Vini |
|