sql server - Regular expressions in TSQL -
in cells of column e_vis_name
have organization structure divisions divided \
symbol, e.g.
- moscow\direction
- yaroslavl\sales
- omsk\commercial center\sales
i need cut after first \ symbol following result:
- moscow
- yaroslavl
- omsk
how can it?
you can use combination of left , charindex this:
select left(colname, charindex('\', colname)-1) table
edit: in case don't have \
symbol, if want grab whole column instead can this:
select case when charindex('\', colname) > 0 left(colname, charindex('\', colname)-1) else isnull(colname, '') end table
this says, "if there \
, take characters point, otherwise take whole column. , if column null
set empty string."
i'm sure can adapt purposes.
Comments
Post a Comment