拆分的冒号在SQL Server
我在SQL表中的列这将有这样的数据:拆分的冒号在SQL Server
“学院:皇后学院”或“大学:昆士兰大学的”
文本之前“:”可能会有所不同。那么,我如何才能选择“:”之前的文本和之后的文本“:(空格)”?
你或许应该考虑把你的表到first normal form而不是存储2个数据在同一列...
;with yourtable as
(
select 'College: Queenstown College' as col UNION ALL
select 'University: University of Queensland'
)
select
left(col,charindex(': ',col)-1) AS InstitutionType,
substring(col, charindex(': ',col)+2, len(col)) AS InstitutionName
from yourtable
非常感谢。这是作品.... – 2010-10-02 09:25:38
可以在“:
@Wee - 是的。请参阅编辑。 – 2010-10-02 09:40:42
使用charindex
和substring
功能:
substring(theField, 1, charindex(':', theField) - 1)
什么数据库版? – 2010-10-02 09:20:45
MS SQL 2005 .... – 2010-10-02 09:22:08