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

关于存储过程!求大神救急!!
有这么几张表
ModelNameInfo表(ModelID,ModelName)
ModelInfo表(ID,ModelID,ModelFieldID)
ModelFieldInfo表(ModelFieldID,ModelFieldName)
FieldInfo表(FieldID,ModelFieldID,FieldContext,ModelID)
 根据ModelID查找ModelFieldID   把每一个不同ModelFieldID的值所对应的不同的FieldContex值 存到相应的ModelFieldID对应的ModelFieldName 的列中 
 要用存储过程实现
有哪位大大会?救急啊!!

------解决方案--------------------
最后返回的表能是
 [项目](ModelFieldName)        [金额](ModelFieldName)   [时间](ModelFieldName)
      一月(FieldContext)           200(FieldContext)     2012年(FieldContext)这样么

if object_id('Tempdb..#temp') is not null drop table #temp
create table #temp(
id int identity(1,1) not null,
col1 nvarchar(100) null,
......--自己定义吧
)

--查询结果,插入临时表:
Insert Into #temp(col1,col2,col3...) select 你的字段1,字段2 ,字段3 ... from 你的汇总表
where ....

------解决方案--------------------
你查出来的ModelFieldName是不是具体的那几项啊?,如果是你就可以定义固定表结构的临时表了,如果不是就得根据查询的内容动态生成表结构了 怎么弄自己得研究一下啊 呵呵