使用sql -followup Q拆分alpha和数字

时间:2018-01-24 12:14:02

标签: sql sql-server ssis

这实际上是对这里提到的主题的后续问题: split alpha and numeric using sql 面对类似的问题,我调整@ knkarthick24(有机会说tnx!)查询我的需求几乎完美(我有“2,500”而非“2 500”)如下:

SELECT [Quantity]
    ,substring(replace(subsrtunit, ',', ''), PATINDEX('%[0-9.]%', replace(subsrtunit, ',', '')) + 1, len(subsrtunit)) AS unit
    ,LEFT(replace(subsrtnumeric, ',', ''), PATINDEX('%[^0-9.]%', replace(subsrtnumeric, ',', '') + 't') - 1) AS num
FROM (
    SELECT [Quantity]
        ,subsrtunit = SUBSTRING([Quantity], posofchar, LEN([Quantity]))
        ,subsrtnumeric = SUBSTRING([Quantity], posofnumber, LEN([Quantity]))
    FROM (
        SELECT [Quantity]
            ,posofchar = PATINDEX('%[^0-9.]%', replace([Quantity], ',', ''))
            ,posofnumber = PATINDEX('%[0-9.]%', replace([Quantity], ',', ''))
        FROM [OPI].[dbo].[MRRInvoices]
        WHERE DocumentNum IS NOT NULL
        ) d
    ) t

唯一剩下的就是处理负值。

现在,我在数量字段(-1.00 GB)中获得负值的结果是单位字段中的(.00 GB)和(1.00)中的num字段。

另外,有没有人知道如何翻译"它在SSIS中的派生列? 可以" Findstring"在SSIS中取代PATINDEX?

提前谢谢大家。

! 1 [IMG]

0 个答案:

没有答案
相关问题