开发者

Row convert to column in sql server 2005?

开发者 https://www.devze.com 2022-12-10 05:24 出处:网络
My table value is Esinoymworkeddaysname 120090625a 120090724a 120090827a 220090622b 220090725....b I nedd out 开发者_开发技巧output is

My table value is

    Esino  ym       workeddays  name
      1   200906        25        a 
      1   200907        24        a
      1   200908        27        a 
      2   200906         22       b
      2   200907        25....    b

I nedd out 开发者_开发技巧output is

     Esino   ym1     ym2    ym3      w1    w2   w3   name
      1      200906  200907 200908  25     24   27   a
      2      200906  200907  200908  22    25    21   b..

Condition is

  1. The ym is my input i given between month for dynamic for eg 200906 to 200912 or 200901 to 200906
  2. workeddays this also depend upon employee presents


You can use pivoting - have a look at this question, very close to your scenario.


you can do this sort of thing using PIVOT


Solution is Dynamic Pivoting. Have a look Problem in dynamic pivoting + sql server 2005

0

精彩评论

暂无评论...
验证码 换一张
取 消