0

データを列に分けたいのですが、データは

column1
1.1.1 Eastern express highway
1.1.2 weater way
2.1 water
2.1.2 land
2.2 sand

私の出力は

column1      column2       column3
1.1            1           Eastern express highway
1.1            2            weater way
2.1            0            water
2.1            2            land
2.2            0            sand
4

3 に答える 3

0
SELECT
    SUBSTRING(ProductDescription, 1,
        CHARINDEX(' - ', ProductDescription) - 1
    ) AS Field1,
    SUBSTRING(ProductDescription,
        CHARINDEX(' - ', ProductDescription) + 3,
        CHARINDEX(' - ', ProductDescription,
            CHARINDEX(' - ', ProductDescription) + 3
        ) - (CHARINDEX(' - ', ProductDescription) + 3)
    ) AS Field2,
    SUBSTRING(ProductDescription,
        CHARINDEX(' - ', ProductDescription,
            CHARINDEX(' - ', ProductDescription) + 3) + 3,
        LEN(ProductDescription)
    ) AS Field3,
    ProductDescription
FROM your_table
于 2012-09-15T12:00:02.920 に答える
0

なぜこのようにしたいのかわかりませんが、これはあなたのサンプルではうまくいきます。試す

SELECT
  substring(section,1,3) as column1,
  CASE WHEN LEN(section)<5 THEN '0'
  ELSE
     SUBSTRING(section,5,1)
  END as column2
FROM MyTable
于 2012-09-15T12:12:49.683 に答える