如何仅选择出现在 SQL Select 语句中特定符号之前的字符 [英] How to select only the characters appearing before a specific symbol in a SQL Select statement

查看:25
本文介绍了如何仅选择出现在 SQL Select 语句中特定符号之前的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数据库中有这样的字符串:

I have strings in a database like this:

firstname.lastname@email.com/IMCLientName

而且我只需要出现在@ 符号之前的字符.

And I only need the characters that appear before the @ symbol.

我试图在 SQL 中找到一种简单的方法来做到这一点.

I am trying to find a simple way to do this in SQL.

推荐答案

DECLARE @email VARCHAR(100)
SET @email = 'firstname.lastname@email.com/IMCLientName'

SELECT SUBSTRING(@email,0, CHARINDEX('@',@email))

这篇关于如何仅选择出现在 SQL Select 语句中特定符号之前的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆