Skip to content
Advertisement

Custom String Conversion

I want to convert a string that can have two formats.

Example

  • 1090512300 to 9.5.123
  • 1090501300 to 9.5.13

The first string (1090512300) will always have the same length but the second(9.5.123) string won’t.

The conversion logic is as follows 1 xx yy zzz 00
So string 1 will be 1xxyyzzz00 and string 2 xx.yy.zzz where all zeros have been removed.

I tried using a number formatting but it doesn’t work correctly due to the fact string 2 won’t have the same length every time.

I would prefer a SQL function that can perform this conversion but I do not know how this will be done.

I came up with the following code in C#.

How would this be translated to either VBA or SQL.

Advertisement

Answer

With MSAccess I would probably use MID, CINT AND CSTR:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement