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

解决方案 »

  1.   


    create proc procName(
     @ModelID int
    )
    as
    begin
    update ModelFieldInfo set ModelFieldName=FieldContext
    from FieldInfo
    where ModelFieldID=(select ModelFieldID where ModelID=@ModelID)
    end
      

  2.   

    create proc myProc
    (
      @modelid    int
    )
    as
      insert into modelfieldinfo    select modelfieldid,fieldcontext from fieldinfo where
     modelfieldid in (select modelfieldid from modelinfo where modelid=@modelid ) 
      

  3.   

    这个不行  我是想把里边的ModelFieldID对应的ModelFieldName值作为列名 进行存储
      

  4.   

    上面的命令把表modelfieldinfo 换成自己创建一个临时表,再返回该临时表就ok了
      

  5.   

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

  6.   

    最后返回的表能是
     [项目](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 ....
      

  7.   

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