从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