sql server 2014 combining data with column name -


i have table this

customerno |  8-10  | 10-12 | 12-14     |    14-16   |  16-18   |     18-20|      1        null     null    thursday       null       null         null     2        friday   null     null          null       wednesday     monday 

i want table based on above table

 customerno | monday(8-10)| monday(10-12)| monday(12-14) |         |friday(18-20)  1               false         false            false                    false 2              false           false           false                     false 

true if customer called on time , day

how should that?

its long code, not find other way so:

declare @customer table ( customerid int, [monday(8-10)] varchar(10),[monday(10-12)] varchar(10),[monday(12-14)] varchar(10), [monday(14-16)] varchar(10),[monday(16-18)] varchar(10),[monday(18-20)] varchar(10), [tuesday(8-10)] varchar(10),[tuesday(10-12)] varchar(10),[tuesday(12-14)] varchar(10), [tuesday(14-16)] varchar(10),[tuesday(16-18)] varchar(10),[tuesday(18-20)] varchar(10), [wednesday(8-10)] varchar(10),[wednesday(10-12)] varchar(10),[wednesday(12-14)] varchar(10), [wednesday(14-16)] varchar(10),[wednesday(16-18)] varchar(10),[wednesday(18-20)] varchar(10), [thursday(8-10)] varchar(10),[thursday(10-12)] varchar(10),[thursday(12-14)] varchar(10), [thursday(14-16)] varchar(10),[thursday(16-18)] varchar(10),[thursday(18-20)] varchar(10), [friday(8-10)] varchar(10),[friday(10-12)] varchar(10),[friday(12-14)] varchar(10), [friday(14-16)] varchar(10),[friday(16-18)] varchar(10),[friday(18-20)] varchar(10) ) declare @id int,@810 varchar(10),@1012 varchar(10),@1214 varchar(10),@1416 varchar(10),@1618 varchar(10),@1820 varchar(10) declare @monday810 varchar(10),@monday1012 varchar(10),@monday1214 varchar(10) declare @monday1416 varchar(10),@monday1618 varchar(10),@monday1820 varchar(10) declare @tuesday810 varchar(10),@tuesday1012 varchar(10),@tuesday1214 varchar(10) declare @tuesday1416 varchar(10),@tuesday1618 varchar(10),@tuesday1820 varchar(10) declare @wednesday810 varchar(10),@wednesday1012 varchar(10),@wednesday1214 varchar(10) declare @wednesday1416 varchar(10),@wednesday1618 varchar(10),@wednesday1820 varchar(10) declare @thursday810 varchar(10),@thursday1012 varchar(10),@thursday1214 varchar(10) declare @thursday1416 varchar(10),@thursday1618 varchar(10),@thursday1820 varchar(10) declare @friday810 varchar(10),@friday1012 varchar(10),@friday1214 varchar(10) declare @friday1416 varchar(10),@friday1618 varchar(10),@friday1820 varchar(10)  declare c cursor  select customerno,[8-10],[10-12],[12-14],[14-16],[16-18],[18-20] customer open c fetch next c @id,@810,@1012,@1214,@1416,@1618,@1820 while @@fetch_status=0 begin ----// 8-10 //----------     if @810 '%monday%'     set  @monday810='true'     else if @810 '%tuesday%'       set  @tuesday810='true'     else if @810 '%wednesday%'     set  @wednesday810='true'     else if @810 '%thursday%'      set  @thursday810='true'     else if @810 '%friday%'        set  @friday810='true'     else          begin             set  @monday810='false'             set  @tuesday810='false'             set  @wednesday810='false'             set  @thursday810='false'             set  @friday810='false'         end ----// 10-12 //----------     if @1012 '%monday%'        set  @monday1012='true'     else if @1012 '%tuesday%'      set  @tuesday1012='true'     else if @1012 '%wednesday%'        set  @wednesday1012='true'     else if @1012 '%thursday%'     set  @thursday1012='true'     else if @1012 '%friday%'       set  @friday1012='true'     else          begin             set  @monday1012='false'             set  @tuesday1012='false'             set  @wednesday1012='false'             set  @thursday1012='false'             set  @friday1012='false'         end  ----// 12-14 //----------     if @1214 '%monday%'        set  @monday1214='true'     else if @1214 '%tuesday%'      set  @tuesday1214='true'     else if @1214 '%wednesday%'        set  @wednesday1214='true'     else if @1214 '%thursday%'     set  @thursday1214='true'     else if @1214 '%friday%'       set  @friday1214='true'     else          begin             set  @monday1214='false'             set  @tuesday1214='false'             set  @wednesday1214='false'             set  @thursday1214='false'             set  @friday1214='false'         end  ----// 14-16//----------     if @1416 '%monday%'        set  @monday1416='true'     else if @1416 '%tuesday%'      set  @tuesday1416='true'     else if @1416 '%wednesday%'        set  @wednesday1416='true'     else if @1416 '%thursday%'     set  @thursday1416='true'     else if @1416 '%friday%'       set  @friday1416='true'     else          begin             set  @monday1416='false'             set  @tuesday1416='false'             set  @wednesday1416='false'             set  @thursday1416='false'             set  @friday1416='false'         end  ----// 16-18 //----------     if @1618 '%monday%'        set  @monday1618='true'     else if @1618 '%tuesday%'      set  @tuesday1618='true'     else if @1618 '%wednesday%'        set  @wednesday1618='true'     else if @1618 '%thursday%'     set  @thursday1618='true'     else if @1618 '%friday%'       set  @friday1618='true'     else          begin             set  @monday1618='false'             set  @tuesday1618='false'             set  @wednesday1618='false'             set  @thursday1618='false'             set  @friday1618='false'         end  ----// 18-20 //----------     if @1820 '%monday%'    set  @monday1820='true' else      if @1820 '%tuesday%'      set  @tuesday1820='true'     else if @1820 '%wednesday%'        set  @wednesday1820='true'     else if @1820 '%thursday%'     set  @thursday1820='true'     else if @1820 '%friday%'       set  @friday1820='true'     else          begin             set  @monday1820='false'             set  @tuesday1820='false'             set  @wednesday1820='false'             set  @thursday1820='false'             set  @friday1820='false'         end if @monday810     null set  @monday810 ='true'     if @monday1012    null set  @monday1012  ='true' if @monday1214    null set  @monday1214   ='true'  if @monday1416    null set  @monday1416   ='true'  if @monday1618    null set  @monday1618   ='true'  if @monday1820    null set  @monday1820   ='true'  if @tuesday810    null set  @tuesday810   ='true'  if @tuesday1012   null set  @tuesday1012  ='true'  if @tuesday1214   null set  @tuesday1214  ='true'  if @tuesday1416   null set  @tuesday1416  ='true'  if @tuesday1618   null set  @tuesday1618  ='true'  if @tuesday1820   null set  @tuesday1820  ='true'  if @wednesday810  null set  @wednesday810 ='true'  if @wednesday1012 null set  @wednesday1012='true'  if @wednesday1214 null set  @wednesday1214='true'  if @wednesday1416 null set  @wednesday1416='true'  if @wednesday1618 null set  @wednesday1618='true'  if @wednesday1820 null set  @wednesday1820='true'  if @thursday810   null set  @thursday810  ='true'  if @thursday1012  null set  @thursday1012 ='true'  if @thursday1214  null set  @thursday1214 ='true'  if @thursday1416  null set  @thursday1416 ='true'  if @thursday1618  null set  @thursday1618 ='true'  if @thursday1820  null set  @thursday1820 ='true'  if @friday810     null set  @friday810    ='true'  if @friday1012    null set  @friday1012   ='true'  if @friday1214    null set  @friday1214   ='true'  if @friday1416    null set  @friday1416   ='true'  if @friday1618    null set  @friday1618   ='true'  if @friday1820    null set  @friday1820   ='true'   insert @customer  values ( @id,@monday810 ,@monday1012 ,@monday1214,  @monday1416 ,@monday1618 ,@monday1820,   @tuesday810 ,@tuesday1012 ,@tuesday1214,   @tuesday1416 ,@tuesday1618 ,@tuesday1820,   @wednesday810 ,@wednesday1012 ,@wednesday1214,   @wednesday1416 ,@wednesday1618 ,@wednesday1820,   @thursday810 ,@thursday1012 ,@thursday1214,   @thursday1416 ,@thursday1618 ,@thursday1820,   @friday810 ,@friday1012 ,@friday1214,   @friday1416 ,@friday1618 ,@friday1820 )  fetch next c @id,@810,@1012,@1214,@1416,@1618,@1820 end close c deallocate c  select * @customer 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -