0

I need to find the 1st, 2nd, 3rd and 4th strings after a separator.

For example I need to parse strings that may look like the following:

1
1.2
1.2.3
1.2.3.4
1.10.1.10

Expected results would be:

1,NULL,NULL,NULL
1,2,NULL,NULL
1,2,3,NULL
1,2,3,4
1,10,1,10

This is on Microsoft SQL 2008 R2.

Thanks!

Alan
  • 125
  • 8
  • 1
    2008 (R2) ran *completely* out of support **4 years** ago. It is *long* past time you upgraded by now; using such an outdated version, that has received no security updates and has known vulnerabilities, is a significant and avoidable risk. *Not to mention this is* far *easier on recent versions*. – Thom A Jun 26 '23 at 21:13
  • Totally agree with you Thom. This is actually for a data extract as we migrate to a new system. – Alan Jun 26 '23 at 21:18
  • While asking a question, you need to provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example): (1) DDL and sample data population, i.e. CREATE table(s) plus INSERT T-SQL statements. (2) What you need to do, i.e. logic and your code attempt implementation of it in T-SQL. (3) Desired output, based on the sample data in the #1 above. (4) Your SQL Server version (SELECT @@version;). – Yitzhak Khabinsky Jun 26 '23 at 21:18
  • *"This is actually for a data extract as we migrate to a new system."* Then why not fix the problem and normalise the data too? – Thom A Jun 26 '23 at 21:36
  • `parsename`.... – Salman A Jun 26 '23 at 21:36
  • @SalmanA i think the problem with parsename is that it returns stuff in the wrong order for this task :/ – siggemannen Jun 26 '23 at 21:43
  • 1
    You can do something like this: https://dbfiddle.uk/hcFvpssP I think XML should be supported in 2008 – siggemannen Jun 26 '23 at 21:47
  • Thanks @siggemannen that worked perfectly. – Alan Jun 27 '23 at 13:19

0 Answers0