在大写字母前加空格

Add spaces before capital letter

有谁知道是否可以在字符串中的每个大写字母之前添加 spaces?我有一个 SQL 查询,其中一列的值保存时没有 space,我需要在连接词之间添加 spaces。

例如,我有 CakeStandsUtensils 并希望分成 Cake Stands Utensils

尝试使用谷歌搜索但不确定我是否没有正确问问题,但找不到任何答案... :( 如果之前在这里问过这个问题,我深表歉意...

使用 MS SQL 服务器 2014

这当然不是一个令我引以为豪的查询,但它完成了工作(假设您只关心英语中的大写字母)

SELECT 
LTRIM(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
YourCol COLLATE Latin1_General_100_BIN2
,'A',' A')
,'B',' B')
,'C',' C')
,'D',' D')
,'E',' E')
,'F',' F')
,'G',' G')
,'H',' H')
,'I',' I')
,'J',' J')
,'K',' K')
,'L',' L')
,'M',' M')
,'N',' N')
,'O',' O')
,'P',' P')
,'Q',' Q')
,'R',' R')
,'S',' S')
,'T',' T')
,'U',' U')
,'V',' V')
,'W',' W')
,'X',' X')
,'Y',' Y')
,'Z',' Z')
)
FROM YourTable

以下假定您从 MS Access accdb 文件中打开 table,或者外部链接到被识别为 CurrentDb[=14 的一部分的数据库=] 对象。如果没有,它假定您知道如何连接到特定的外部数据库 and/or 服务器。

'WARNING! This contains no object testing or error checking!

'Connection to open or linked database
Dim db As Dao.Database
Set db = CurrentDb
Dim rs As Dao.Recordset
Set rs = db.OpenRecordset("SELECT * FROM TableName")

'Temporary search and append strings
Dim strField As String
Dim strAppend As String
Dim strUpdate As String

'Begin Record Traversal
rs.MoveFirst
Do While Not rs.EOF
    strField = rs!NoSpacesField
    Debug.Print strField

    'Traverse field characters
    For i = 1 To Len(strField)
        strAppend = Mid(strField, i, 1)

        'Test for capitals and append space. Asc() assumes ascii characters.
        'Use AscW() for Unicode
        If Asc(strAppend) > 64 And Asc(strAppend) < 91 Then
            strAppend = " " & strAppend
        End If
        strUpdate = strUpdate & strAppend
    Next i

    'Trim initial space and update DB field
    strUpdate = LTrim(strUpdate)
    With rs
        .Edit
        !NoSpacesField = strUpdate
        .Update
        Debug.Print !NoSpacesField
    End With
    strUpdate = ""
    rs.MoveNext
Loop
'End Record Traversal

'Cleanup
rs.Close
db.Close