且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 SQL Server 中按字符将字符串拆分为单独的列

更新时间:2023-11-13 19:55:22

可能有几种不同的方法来做到这一点,有些比其他方法更丑陋.这是一个:

There are probably several different ways to do it, some uglier than others. Here's one:

(注:dat = 字符串)

(Note: dat = the string of characters)

select *,
  substring(dat,1,charindex('-',dat)-1) as Section,
  substring(dat,charindex('-',dat)+1,charindex('-',dat)-1) as TownShip,
  reverse(substring(reverse(dat),0,charindex('-',reverse(dat)))) as myRange
from myTable