日期:2014-05-17  浏览次数:20655 次

从Header和line表读数据输出到文本文件,要求1行header数据,多行line数据,求怎么处理
有两个表

表1
Cid,approve_date,Total_Amt
333,2013-07-20,1000
表2
cid,reportno,amt,deptno
333,1,900,D310
333,2,100,D310


输出到文本文件1.txt,要求格式
H 333 2013-07-20 1000
L 1  900  D310
L 2  100  D310

请问应如何处理

------解决方案--------------------
select content from (
  select cid, 0 as reportno,
    'H'
------解决方案--------------------
' '
------解决方案--------------------
cid
------解决方案--------------------
' '
------解决方案--------------------
approve_date
------解决方案--------------------
' '
------解决方案--------------------
total_amt as content from 表1
  union all
  select cid, reportno,
    'L'
------解决方案--------------------
' '
------解决方案--------------------
reportno
------解决方案--------------------
' '
------解决方案--------------------
amt
------解决方案--------------------
' '
------解决方案--------------------
deptno as content from 表2
) order by cid, reportno

如果各列分开也一样,思路不变,
至于结果怎么拷贝到txt,各种方法就不举例了。