Extract email address from string using tsql

后端 未结 6 1459
面向向阳花
面向向阳花 2021-01-13 09:01

I\'m trying to extract email addresses from an existing comments field and put it into its own column. The string may be something like this \"this is an example comment wit

6条回答
  •  日久生厌
    2021-01-13 09:26

    This one line would also work (a bit long line though lol):

    --declare @a varchar(100) 
    --set @a = 'a asfd saasd asdfgh@asd.com wqe z zx cxzc '
    select substring(substring(@a,0,charindex('@',@a)),len(substring(@a,0,charindex('@',@a)))-charindex(' ',reverse(substring(@a,0,charindex('@',@a))))+2,len(substring(@a,0,charindex('@',@a)))) + substring(substring(@a,charindex('@',@a),len(@a)),0,charindex(' ',substring(@a,charindex('@',@a),len(@a))))
    

提交回复
热议问题