簡體   English   中英

SQL Server 2005查詢SUBSTRING和PATINDEX

[英]SQL Server 2005 Query SUBSTRING & PATINDEX

我的數據庫中有三個單詞短語:

例如:“ JKH排水裝置”

有誰知道如何獲得第三個單詞的第一個字母?

我需要提取“單位”一詞的“ U”。

注意我嘗試使用SUBSTRING(Phrase,PATINDEX('%%%',Phrase)+ 1,1)但對我不起作用...

我將其逐步分解,只是為了讓我瘋狂地展示這種方法:

declare @Phrase varchar(100)
set @Phrase = 'JKH Drainage Units'

/* The first space */
select charindex(' ', @Phrase, 1)

/* The second space */
select charindex(' ', @Phrase, charindex(' ', @Phrase, 1) + 1)

/* The first character after the second space */
select substring(@Phrase, charindex(' ', @Phrase, charindex(' ', @Phrase, 1) + 1)+1, 1)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM