谢谢,但可能是我没有说清楚,详细的表肯定另外建好了的,但,怎么样才能把表中的
内容提升为表头呢?
我们常用的SQL语句都是表头就是表头,字段值就是字段值,在ACCESS中可以跨越这道鸿沟,可,SQL SERVER中不支持TRANSFORM ,PIVOT语句啊,我该如何实现???

解决方案 »

  1.   

    试试这个,不行别砍我啊,我只是试一下
    select distinct stuid,
    (select grade from stugrade where stuid=c.stuid and courseid='语文') as '语文',
    (select grade from stugrade where stuid=c.stuid and courseid='数学') as '数学',
    (select grade from stugrade where stuid=c.stuid and courseid='历史') as '历史'
    from stugrade c
      

  2.   

    我想应该可以,但,问题是(不好意思,我又没说清楚),每个班开了多少门课,开那些课,都是不一样的啊! 难道,就没有象ACCESS中那样简单明了的语句吗? :-(
      

  3.   

    相对于SQL 2000来说,Access是小儿科,Access能作到的,SQL 2000肯定能作到,并且效率会高很多,只是你的问题不清楚。
    反正偶是看不懂,嘿嘿
      

  4.   

    如果我没理解错误的话。你需要写存储过程例如:
    select @subject=subject from maindb
    exec('select * from ' + @subject + ');另外,数据库结构设计合理以后,完全不需要搞得这么麻烦,还是下功夫在如何避免出现交叉数据的问题吧。
      

  5.   

    交叉透视表而已,用case轻松解决
    select stuid,
    sum(case courseid when '语文' then grade else 0) as '语文',
    sum(case courseid when '数学' then grade else 0) as '数学',
    sum(case courseid when '历史' then grade else 0) as '历史'
    from stugrade c
    group by stuid
      

  6.   

    有笔误
    select stuid,
    sum(case courseid when '语文' then grade else 0 end) as '语文',
    sum(case courseid when '数学' then grade else 0 end) as '数学',
    sum(case courseid when '历史' then grade else 0 end) as '历史'
    from stugrade c
    group by stuid
    没见你的姓名字段在哪里啊。