問題描述
我有一列字符串,每個字符串包含一個城市、州和數字.
I have a column of strings with a city, state and number in each.
SPOKANE, WA 232/107
LAS VEGAS, NV 232/117
PORTLAND, OR 232/128
還有很多,但我想知道如何刪除此列中的數字并僅顯示城市和州,或者-甚至更好- 刪除數字并將城市和州作為單獨的列.
There are many more than just that, but I am wondering how either I could cut off the numbers in this column and just show the city and state or -even better- cut off the numbers and make city and state a separate column.
對于所有不同的記錄,該列一直采用相同的格式.
The column is in the same format all the way down for all the different records.
謝謝!
推薦答案
無需為您完成所有工作...
Without doing all of the work for you...
城市:列的子字符串,從位置 0 到逗號的第一次出現 - 1.
狀態:列的子字符串,從逗號第一次出現后的 2 個位置到下一個空格的位置......修剪.
City: A substring of the column from position 0, to the first occurence of a comma - 1.
State: A substring of the column from 2 positions after the first occurence of a comma, to the next position that is a space... trimmed.
參見:SUBSTRING()
、CHARINDEX()
、PATINDEX()
這篇關于SQL如何截斷字符串的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!