数据表A: 列为FormID,FieldName,FieldDate,一个FormID下有多个FielName
如:
FormID FieldName FieldDate
1 编号 2
1 发起人 张三
1 发起时间 2007-1-12
1 内容 你好
数据表B:列为FormID,CreateDate,CreateName现在想要一个视图或存储过程将AB表根据FormID拉成横向显示,如
FormID Code Name Date Content
1 2 张三 2007-1-12 你好
2 3 里司 2007-1-13 我好请问如何表达???
谢谢
如:
FormID FieldName FieldDate
1 编号 2
1 发起人 张三
1 发起时间 2007-1-12
1 内容 你好
数据表B:列为FormID,CreateDate,CreateName现在想要一个视图或存储过程将AB表根据FormID拉成横向显示,如
FormID Code Name Date Content
1 2 张三 2007-1-12 你好
2 3 里司 2007-1-13 我好请问如何表达???
谢谢
SELECT iwftask.*, VIWDICTASKSTATE.NAME AS taskstatename
FROM iwftask LEFT OUTER JOIN (Select ID From dicType where DicName='') DicType ON iwftask.taskstate = DicType.ID
sum(decode(FieldName, 发起人, FieldDate, null)) Name,
sum(decode(FieldName, 发起时间, FieldDate, null)) Date,
sum(decode(FieldName, 内容, FieldDate, null)) Content
from A
group by FormID
sum(decode(FieldName, 发起人, FieldDate, null)) Name,
sum(decode(FieldName, 发起时间, FieldDate, null)) Date,
sum(decode(FieldName, 内容, FieldDate, null)) Content
from A
group by FormID;多列的话,按照格式自行添加即可