2 Replies Latest reply: Aug 10, 2012 9:17 AM by Maxime Soudier RSS

    Rename field

    Giorgia Michieli

      Hi,

      I'm trying to do something like this:

       

      if campo='account' then campo rename to c_account

      then if campo='lead' then campo as c_lead

      then if campo='contact' then campo as c_contact

       

      So, I would like to rename the field depending on values that cointains: if it contains n possible values i would like to obtaining n new fields.

      Can I do this in qv script? How?

       

      Thank you!

        • Re: Rename field
          Giorgia Michieli

          Stupid question, I'm sorry.

          I do in this way:

           


          if (relmodule='Accounts', relcrmid) as c_azienda,

          if (relmodule='Leads', relcrmid) as c_lead,

          if (relmodule='Contacts', relcrmid) as c_contatto,
          • Re: Rename field

            Hi,

             

            I think that this solution could work (I suppose that your field is in a table "table_name") :

             

            // Get the list of different values in the field

            Temp_List_Values:

            LOAD CONCAT(DISTINCT campo, chr(39)&','&chr(39)) as temp_list

            RESIDENT table_name;

             

            LET LIST_OF_CAMPO = chr(39) & peek('temp_list',0,'Temp_List_Values') & chr(39);

             

            FOR EACH i IN $(LIST_OF_CAMPO)

             

                 LET FINAL_FIELD_NAME = 'c_$(i)';

             

                 $(FINAL_FIELD_NAME):

                 LOAD campo as "$(FINAL_FIELD_NAME)"

                 RESIDENT table_name

                 WHERE campo = '$(i)';

             

            NEXT

             

            This script create one table per value of campo with the correct. But you could add more fields and do a work to build your model.