2016-02-15 87 views
-1

我有一個名爲「PONDAILY」的表,它具有名爲「PONCOM」的列。 「PONCOM」具有字符串內容,就像文本筆記,我只需要從字符串中提取SO編號,下面是列表中數據如何顯示和突出顯示的示例,是我期望檢索的示例。我無法使用任何UDF,因爲我只能讀取SQL服務器的訪問權限。SQL Server:從特定列中的字符串獲取SO編號

DELETE TO EXPEDITE ON NEW STO FOR M/D SO SAP# **5000068**. HN04 

DELETING FOR M/D SO#**4500000762** KF 03-31 

REDUCED BY 1 TO EXPEIDTE FOR M/D SO**100471**...CSR EM...HN04040 

REDUCED QTY BY 1 TO EXPEDITE FOR M/D SO SAP **100551**. HN040300 

REDUCED QTY BY 1 TO EXPEDITE FOR M/D SO SAP **100551**/1. HN040300 

REDUCED BY QTY1 FOR M/D SO# **105707** 

REDUCED QTY BY 3 FOR M/D SO#S **5003785**, 5003786, 5003791 KF 0 

我想只得到粗體

回答

0

中包含如果我理解正確的問題:

select substring(PONCOM, t2.num, case when t3.not_num < t2.num then 8000 else t3.not_num - t2.num end) 
    from PONDAILY p 
    cross apply (select charindex('SO', PONCOM, 1)) t1(so) 
    cross apply (select patindex('%[0-9]%', substring(PONCOM, t1.so, 8000)) + t1.so - 1) t2(num) 
    cross apply (select patindex('%[^0-9]%', substring(PONCOM, t2.num, 8000)) + t2.num - 1) t3(not_num) 
+0

我覺得這是工作完美,但我沒有看到輸出這樣的線路: CCdddD 02,7001032 hftfLIPS,SO ** 2300 **。RW245588,SO#** 1000471 *** KFE 040400 –

+0

這很奇怪,因爲我看到了這一行的結果:「CCdddD 02,7001032 hftfLIPS,SO2300.RW245588,SO# 1000471 * KFE 040400「 – xLiSPirit

+0

好的非常感謝。我們可以避開只有數字的字段,因爲它只返回數字。例如0085128558是字段值和列返回值是0085128558 –

相關問題