我希望找到一种从espn
abcd@espn.com
的方法
我在Microsoft SQL Server中工作。有谁知道怎么写substring
来完成这个?
谢谢!
答案 0 :(得分:0)
试试这个
select SUBSTRING(
'xx.abcd@espn.com', --input string
charindex('@', 'xx.abcd@espn.com') + 1,
(len('xx.abcd@espn.com')-charindex('@', 'xx.abcd@espn.com'))-4
)
答案 1 :(得分:0)
DECLARE @emailAddress TABLE (emailAddress VARCHAR(255))
INSERT @emailAddress (emailAddress)
VALUES ('abcd@espn.com'),
('ab.cd@taylormade.edu'),
('notanemailaddress')
SELECT IIF(emailAddress LIKE '%@%.%', -- Confirm it has valid structure
SUBSTRING(emailAddress,
CHARINDEX('@',emailAddress)+1,
CHARINDEX('.',emailAddress,CHARINDEX('@',emailAddress))-(CHARINDEX('@',emailAddress)+1)), --Extract the domain
NULL) -- Provide default value if not an emailAddress
AS emailDomain
FROM @emailAddress
这会考虑无效的emailAddresses值,并在遇到无效值时返回NULL
(或者放在那里的任何内容)。
答案 2 :(得分:-1)
这应该有效:
<script type="text/javascript" src="d3.v3.min.js"> </script>
<script>
var width = 900,
height = 590;
var svg = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height)
var links = [
{source: 'H', target: 'I'},
{source: 'H', target: 'J'},
{source: 'I', target: 'J'},
{source: 'J', target: 'K'},
];
var nodes = {};
links.forEach(function(link) {
link.source = nodes[link.source] ||
(nodes[link.source] = {name: link.source});
link.target = nodes[link.target] ||
(nodes[link.target] = {name: link.target});
});
var force = d3.layout.force()
.size([width, height])
.nodes(d3.values(nodes))
.links(links)
.on('tick', tick)
.linkDistance(100)
.gravity(.15)
.friction(.8)
.linkStrength(1)
.charge(-425)
.chargeDistance(600)
.start();
var link = svg.selectAll('.link')
.data(links)
.enter().append('line')
.attr('class', 'link');
var node = svg.selectAll('.node')
.data(force.nodes())
.enter().append('circle')
.attr('class', 'node')
.attr('r', width * 0.01)
function tick(e) {
node.attr('cx', function(d) { return d.x; })
.attr('cy', function(d) { return d.y; })
.call(force.drag);
link.attr('x1', function(d) { return d.source.x; })
.attr('y1', function(d) { return d.source.y; })
.attr('x2', function(d) { return d.target.x; })
.attr('y2', function(d) { return d.target.y; });
};
</script>
答案 3 :(得分:-1)
你正在寻找这个。
Select substring(@email,charindex('@', @email)+1,
charindex('.',right(@email,len(@email) - charindex('@', @email)))-1)
电子邮件地址可以在.
之前和之后多次包含@
,这应该会在@