7 Replies Latest reply: May 8, 2014 9:41 PM by jagan mohan rao appala RSS

    how to concatenate and compute new column

      Hi,

       

      I want to concatenate 2 tables with the same column names and compute new columns from existing columns. If I do this:

      Sector0:

      LOAD *,

           Time([Date Confirmed],'hh:mm:ss') as Time,

           Date([Date Confirmed],'M/D/YYYY') as [Actual Date],

           If(time#([Time],'hh:mm:ss')<time#('10:00:00','hh:mm:ss'),1,0) as [Before 10am],

           If(time#([Time],'hh:mm:ss')>time#('22:00:00','hh:mm:ss'),1,0) as [After 10pm]

      FROM

      <file>

      (txt, codepage is 1252, embedded labels, delimiter is '|', msq);


      Concatenate(Sector0)

      LOAD *,

           Time([Date Confirmed],'hh:mm:ss') as Time,

           Date([Date Confirmed],'M/D/YYYY') as [Actual Date],

           If(time#([Time],'hh:mm:ss')<time#('10:00:00','hh:mm:ss'),1,0) as [Before 10am],

           If(time#([Time],'hh:mm:ss')>time#('22:00:00','hh:mm:ss'),1,0) as [After 10pm]

      FROM

      <file2>

      (biff, embedded labels, table is Sheet1$);

       

      there will be the error messages "Field not found - <Time>" and "Table not found Concatenate(Sector0)...".

      But if the code is like the one below, the script can successfully load.

       

      Sector0:

      LOAD *,

           Time([Date Confirmed],'hh:mm:ss') as Time,

           Date([Date Confirmed],'M/D/YYYY') as [Actual Date]

      FROM

      <file>

      (txt, codepage is 1252, embedded labels, delimiter is '|', msq);

       

      Concatenate(Sector0)

      LOAD *,

           Time([Date Confirmed],'hh:mm:ss') as Time,

           Date([Date Confirmed],'M/D/YYYY') as [Actual Date],

           If(time#([Time],'hh:mm:ss')<time#('10:00:00','hh:mm:ss'),1,0) as [Before 10am],

           If(time#([Time],'hh:mm:ss')>time#('22:00:00','hh:mm:ss'),1,0) as [After 10pm]

      FROM

      <file2>

      (biff, embedded labels, table is Sheet1$);

       

      Thanks.

       

      Rachel

        • Re: how to concatenate and compute new column
          jagan mohan rao appala

          Hi,

           

          In First table do you have column named Time in the table?  If there is no Time column then you will get this error.

           

          Regards,

          Jagan.

            • Re: how to concatenate and compute new column

              Yes, I created a Time column in the first table Sector0

               

              Sector0:

              LOAD *,

                   Time([Date Confirmed],'hh:mm:ss') as Time

                • Re: how to concatenate and compute new column
                  jagan mohan rao appala

                  Hi,

                   

                  The error is because of this two lines

                   

                  If(time#([Time],'hh:mm:ss')<time#('10:00:00','hh:mm:ss'),1,0) as [Before 10am],

                       If(time#([Time],'hh:mm:ss')>time#('22:00:00','hh:mm:ss'),1,0) as [After 10pm]


                  In that Time is used as a Column, it should be like this


                  Sector0:

                  LOAD

                  *,

                  If(time#([Time],'hh:mm:ss')<time#('10:00:00','hh:mm:ss'),1,0) as [Before 10am],

                       If(time#([Time],'hh:mm:ss')>time#('22:00:00','hh:mm:ss'),1,0) as [After 10pm];

                  LOAD *,

                       Time([Date Confirmed],'hh:mm:ss') as Time,

                       Date([Date Confirmed],'M/D/YYYY') as [Actual Date]    

                  FROM

                  <file>

                  (txt, codepage is 1252, embedded labels, delimiter is '|', msq);


                  Regards,

                  Jagan.



                    • Re: how to concatenate and compute new column

                      Ok. But i have another column to add and if I put this, it does not work.

                      There is this error message "Field not found - <Before 10am>

                       

                      LOAD

                      *,

                           If(time#([Time],'hh:mm:ss')<time#('10:00:00','hh:mm:ss'),1,0) as [Before 10am],

                           If(time#([Time],'hh:mm:ss')>time#('22:00:00','hh:mm:ss'),1,0) as [After 10pm],

                           If([Before 10am]+[After 10pm]>0,'Night Shift','Day Shift') as Shift;

                      LOAD *,

                           Time([Date Confirmed],'hh:mm:ss') as Time,

                           Date([Date Confirmed],'M/D/YYYY') as [Actual Date]  

                      FROM

                      <file>

                      (txt, codepage is 1252, embedded labels, delimiter is '|', msq);

                        • Re: how to concatenate and compute new column
                          Massimo Grossi

                          add another load (below, not bold)

                           

                          load

                                    *,

                                    If([Before 10am]+[After 10pm]>0,'Night Shift','Day Shift') as Shift;

                          LOAD

                          *,

                               If(time#([Time],'hh:mm:ss')<time#('10:00:00','hh:mm:ss'),1,0) as [Before 10am],

                               If(time#([Time],'hh:mm:ss')>time#('22:00:00','hh:mm:ss'),1,0) as [After 10pm]

                               // If([Before 10am]+[After 10pm]>0,'Night Shift','Day Shift') as Shift;

                          LOAD *,

                               Time([Date Confirmed],'hh:mm:ss') as Time,

                               Date([Date Confirmed],'M/D/YYYY') as [Actual Date] 

                          FROM

                          <file>

                          (txt, codepage is 1252, embedded labels, delimiter is '|', msq);

                          • Re: how to concatenate and compute new column
                            jagan mohan rao appala

                            Hi,

                             

                            In the top load statement you dont have [Before 10am] and [After 10pm] columns, that is why you are getting the errrors.

                             

                            Try this

                             

                            LOAD

                            *,

                                 If([Before 10am]+[After 10pm]>0,'Night Shift','Day Shift') as Shift;

                            LOAD

                            *,

                                 If(time#([Time],'hh:mm:ss')<time#('10:00:00','hh:mm:ss'),1,0) as [Before 10am],

                                 If(time#([Time],'hh:mm:ss')>time#('22:00:00','hh:mm:ss'),1,0) as [After 10pm];

                            LOAD *,

                                 Time([Date Confirmed],'hh:mm:ss') as Time,

                                 Date([Date Confirmed],'M/D/YYYY') as [Actual Date] 

                            FROM

                            <file>

                            (txt, codepage is 1252, embedded labels, delimiter is '|', msq);

                             

                            Regards,

                            Jagan.

                    • Re: how to concatenate and compute new column
                      Marco Wedel

                      to sum it up, you can't use a field name in the same load where it is created (as well as e.g. in it's where clause).

                      Use preceding loads in these cases.