Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
hkg_qlik
Creator III
Creator III

Trim Field Values

Hi,

I need to trim some field values in a product table. All products are having their name starting with 'PR'.

Example (PRODUCT TABLE): PRFOOD, PRDRINKS, PDFLAVORS etc

I need to remove 'PR' from front of all above names while loading the script.

Regards,

H

1 Solution

Accepted Solutions
kangaroomac
Partner - Creator II
Partner - Creator II

Hiya,

Another option could be:

Load
    
ProductID
     ,
SubField(ProductName,'PR',2)     AS NewProductName;

SQL SELECT
      Product ID
     , ProductName
FROM ProductsTable;

Hope this helps.

View solution in original post

6 Replies
stevedark
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi,

You simply need to alias the field names using the AS statement, eg:

LOAD
  PRFOOD as Food,

   PRDRINKS as Drinks,

   PRFLAVORS as Flavors,

When I have many many fields that I have to do this sort of thing for I tend to paste the field list into Excel then in an adjoining cell have an expression to build the load script for me, eg:

=CONCATENATE("     ", A1, " AS [", PROPER(MID(A1, 3, 99)), "],")

This can then be copied down for each field in Excel, the column containing all the values can then be copied and pasted directly into your load script.

Hope that helps,

Steve

hkg_qlik
Creator III
Creator III
Author

Hi Steve,

My table looks like this:

PRODUCT TABLE has following values where I need to remove PR

PRFOOD

PRDRINKS

PRFLAVORS

Thanks,

H

Sokkorn
Master
Master

Hi H,

Maybe I'm got you wrong, but let try:

[Product]:

Load

     ProductID,

     ProductName,

     Mid(ProductName,3,Len(ProductName))     AS NewProductName;

Select ProductID,ProductName From PRODUCT;

Regards,

Sokkorn

Not applicable

Are you taking about Field Names or Field Values?

If you want rename the Field names, just follow the Steve procedure. If you want change the field values, Please use RIGHT function: RIGHT(FIELNAME, LEN(FIELDNAME)-2) AS FIELDNAME

kangaroomac
Partner - Creator II
Partner - Creator II

Hiya,

Another option could be:

Load
    
ProductID
     ,
SubField(ProductName,'PR',2)     AS NewProductName;

SQL SELECT
      Product ID
     , ProductName
FROM ProductsTable;

Hope this helps.

stevedark
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi,

Sorry, I thought those values were column names. Sokkorn's suggestion is

fine.

Mid(PRODUCT, 3, 99) as Product,

Steve