假设 a表:结构: id,name,grade,sex,address
 b表中结构: id ,name,grade,score1,score2等信息
 
存储过程 获取  id ,score1,score2,如何使用a表 和存储过程获取的数据,将b表 补充完整,即:name, grade  从a表获得表打我,数据库 不是我设计的

解决方案 »

  1.   

    只能假设b表中id,score1,score2都已经存在,而且id与a表id对应.
    则:
    update t2 set name=t2.name,grade=t2.grade from b t2 inner join a t1 on a.id=b.id
      

  2.   

    两个表的关联字段是ID?update b
    set name=a.name,grade=a.grade 
    from a,b 
    where a.ID=b.ID
      

  3.   

    问题是 b表的score 是必填数据哎。
      

  4.   

    b表的 score是必填数据 而且一开始表内无数据
      

  5.   

    insert into b(iname,grade) select name,grade from a--存储过程的插入临时表create table #tb (id int ,score1 int ,score2 int)insert into #tb exec(@sql)insert into b(id,score1,score2) select * from #tb
      

  6.   

    declare @a table
    (
      id varchar(50),
      score1 varchar(50),
      score2 varchar(50)
    );--假设存储过程的名称为dbo.sp_get
    INSERT INTO @a
      exec dbo.sp_get;with c1
    as
    (
      select id,score1, score2
      from @a
    ),
    c_complate
    as
    (
       select id, score1, score2, a.name, a.grade  --此时可以获取一条完整数据项
       from c1
         join a
         on c1.id=a.id
    )
    Select id, score1, score2, name, grade --使用SELECT INTO将数据项插入临时表#T
    INTO #T
    from c_complate
    ----后续操作
    看看有没有什么不恰当的地方,呵呵!写CTE写习惯了,感觉很方便……
      

  7.   

    存储过程返回结果及传入参数是什么?
    是否是不传入参数时,返回所有ID的成绩?
    还是只能返回传入ID的成绩?如果能返回所有,楼上正解
    只能返回指定ID,可能要使用游标