SELECT     tDriverAppraise.P_NO_NO, 
   tAppraiseSet.ID, 
   tAppraiseSet.AppraiseName, 
   CAR_PS_TRACK.DRIVER_ID, 
   DRIVER_MANAGEMENT.DRIVER_NAME, 
   CAR_PS_TRACK.MOTOR_NO, 
   tDriverAppraise.AppraiseValue,
   tDriverAppraise.AppraiseRatio
FROM       DRIVER_MANAGEMENT 
INNER JOIN CAR_PS_TRACK ON DRIVER_MANAGEMENT.DRIVER_ID = CAR_PS_TRACK.DRIVER_ID 
INNER JOIN tDriverAppraise ON CAR_PS_TRACK.P_OP_NO = tDriverAppraise.P_NO_NO 
INNER JOIN tAppraiseSet ON tDriverAppraise.AppraiseTyep = tAppraiseSet.ID
根据tAppraiseSet.AppraiseName变成横表

解决方案 »

  1.   

    http://www.cnblogs.com/zhangzt/archive/2010/07/29/1787825.html
      

  2.   

    感觉你的这个不需要吧,直接分组就行了。
    直接在语句后面加上
    group by tAppraiseSet.AppraiseName;
      

  3.   

    这儿有个类似的,你看看
    http://topic.csdn.net/u/20110427/15/77f8a9f2-a401-4c8c-b3b1-090a7ac33f3b.html
      

  4.   

     declare @AppraiseName varchar(50)
     declare @strsql varchar(2000)
     set @strsql='select AppraiseName '
     declare cur cursor
     for
     select distinct  AppraiseName from tAppraiseSet
     open cur
     fetch from cur into @AppraiseName 
     while @@FETCH_STATUS = 0
     begin set @strsql=@strsql+', sum(case AppraiseName when '''+@AppraiseName+''' then P_NO_NO end)as '+ @AppraiseName
     fetch next from cur  into @AppraiseName
     end
     close cur
     DEALLOCATE cur
     print @strsql
     exec(@strsql)
      

  5.   

    set @strsql=@strsql+', sum(case AppraiseName when '''+@AppraiseName+''' then P_NO_NO end)as '+ @AppraiseName
    这哪不对
      

  6.   

    只有case,少了else
    set @strsql=@strsql+', sum(case AppraiseName when '''+@AppraiseName+''' then P_NO_NO else 0 end)as '+ @AppraiseName
    这哪不对