Multiplications contained in texts

0

How to make the multiplications contained in a varchar field? (to get the area in case)

+------------------------------------------------------+
|                     DESCRIÇÃO                        |
+------------------------------------------------------+
|Chapa Térmica 605x745 Speed Chemfree                  |
|Chapa Térmica 665 X 910 Ryobi Fuji                    |
|Chapa Convencional P 4001 605x745 Speed IBF           |
|Chapa Térmica 665 X 910 X 030 sem Processo Ryobii IBF |
|Chapa Térmica 800x1030 Komori Chemfree                |
+------------------------------------------------------+

Looking for a workaround, I found a field with the type of a code for the plates, which contains the dimensions of them:

+--------------+------------------------------------------------------+
|     CODE     |                    DESCRIPTION                       |
+--------------+------------------------------------------------------+
| T605745SPCHE | Chapa Térmica 605x745 Speed Chemfree                 |
| T665910RYJUF | Chapa Térmica 665 X 910 Ryobi Fuji                   |
| C605745SPIBF | Chapa Convencional P 4001 605x745 Speed IBF          |
| T665910RYIBF | Chapa Térmica 665 X 910 X 030 sem Processo Ryobii IBF|
| T8001030KBF  | Chapa Térmica 800x1030 Komori Chemfree               |
+--------------+------------------------------------------------------+

I think my only problem right now is how to handle codes with 6 or 7 numbers to be multiplied. Any suggestions?

    
asked by anonymous 20.02.2015 / 18:24

2 answers

1

I do not know what language you're working on so I'll try to be generic in the answer:

Begin by separating the lines, and at home line use a regular expression to recognize the format, such as:

\b[0-9]\+x[0-9]\+

This is a regular expression of type sed, you can read more at

link

The expression I wrote says: Get an expression beginning with a blank space (\ b) followed by one or more digits ([0-9] +), followed by an x, followed by one or more digits.

You can then split them with a split in the x symbol, ie, separate the two elements, the previous and the posterior to x, then convert them to numbers and simply have the area calculated.

    
20.02.2015 / 20:11
0

With this new column, things have gotten a lot easier. I've done the following:

'Area' = (CONVERT(decimal,SUBSTRING(table.CodItem,2,3))*

        CASE WHEN SUBSTRING(table.CodItem,8,1) LIKE '[0-9]' THEN
            CONVERT(decimal,SUBSTRING(table.CodItem,5,4)) ELSE
            CONVERT(decimal,SUBSTRING(table.CodItem,5,3)) END)/1000000

The function CONVERT and division by /1000000 I used only for conversion from mm² to m2. Thanks!

    
20.02.2015 / 20:41