<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; Selecting Domain from Email Address</title>
	<atom:link href="http://blog.sqlauthority.com/2011/06/18/sql-server-selecting-domain-from-email-address/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2011/06/18/sql-server-selecting-domain-from-email-address/</link>
	<description>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Fri, 17 May 2013 15:26:57 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Rashmita</title>
		<link>http://blog.sqlauthority.com/2011/06/18/sql-server-selecting-domain-from-email-address/#comment-294640</link>
		<dc:creator><![CDATA[Rashmita]]></dc:creator>
		<pubDate>Tue, 05 Jun 2012 13:49:47 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=13248#comment-294640</guid>
		<description><![CDATA[How to get sub string from a string: 
input:- 
1.  /documents/subDocuments/test_123.txt (required result &#039;test&#039;)
2. /documents/subDocuments/test_def_45ddd.txt (required result &#039;test_def&#039;)

I want the sub string between last index of &#039;/&#039; and last index of &#039;_&#039;

Thanks,
Rashmita]]></description>
		<content:encoded><![CDATA[<p>How to get sub string from a string:<br />
input:-<br />
1.  /documents/subDocuments/test_123.txt (required result &#8216;test&#8217;)<br />
2. /documents/subDocuments/test_def_45ddd.txt (required result &#8216;test_def&#8217;)</p>
<p>I want the sub string between last index of &#8216;/&#8217; and last index of &#8216;_&#8217;</p>
<p>Thanks,<br />
Rashmita</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Amit Patel</title>
		<link>http://blog.sqlauthority.com/2011/06/18/sql-server-selecting-domain-from-email-address/#comment-144385</link>
		<dc:creator><![CDATA[Amit Patel]]></dc:creator>
		<pubDate>Tue, 28 Jun 2011 10:59:20 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=13248#comment-144385</guid>
		<description><![CDATA[Hi Pinal,

we need add email validation check in this script because this script is working on @ but some invalid email entered in database table then this scriot is not working as expected.

I have modified it as below.

SELECT RIGHT(Email, LEN(Email) - CHARINDEX(&#039;@&#039;, email)) Domain ,
COUNT(Email) EmailCount
FROM   dbo.email
WHERE  LEN(Email) &gt; 0 and CHARINDEX(&#039;@&#039;, email) &gt; 0
GROUP BY RIGHT(Email, LEN(Email) - CHARINDEX(&#039;@&#039;, email))
ORDER BY EmailCount DESC]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,</p>
<p>we need add email validation check in this script because this script is working on @ but some invalid email entered in database table then this scriot is not working as expected.</p>
<p>I have modified it as below.</p>
<p>SELECT RIGHT(Email, LEN(Email) &#8211; CHARINDEX(&#8216;@&#8217;, email)) Domain ,<br />
COUNT(Email) EmailCount<br />
FROM   dbo.email<br />
WHERE  LEN(Email) &gt; 0 and CHARINDEX(&#8216;@&#8217;, email) &gt; 0<br />
GROUP BY RIGHT(Email, LEN(Email) &#8211; CHARINDEX(&#8216;@&#8217;, email))<br />
ORDER BY EmailCount DESC</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQLAuthority News – Monthly list of Puzzles and Solutions on SQLAuthority.com Journey to SQLAuthority</title>
		<link>http://blog.sqlauthority.com/2011/06/18/sql-server-selecting-domain-from-email-address/#comment-144317</link>
		<dc:creator><![CDATA[SQLAuthority News – Monthly list of Puzzles and Solutions on SQLAuthority.com Journey to SQLAuthority]]></dc:creator>
		<pubDate>Tue, 28 Jun 2011 03:08:23 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=13248#comment-144317</guid>
		<description><![CDATA[[...] SQL SERVER – Selecting Domain from Email Address [...]]]></description>
		<content:encoded><![CDATA[<p>[...] SQL SERVER – Selecting Domain from Email Address [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeetendra</title>
		<link>http://blog.sqlauthority.com/2011/06/18/sql-server-selecting-domain-from-email-address/#comment-144239</link>
		<dc:creator><![CDATA[Jeetendra]]></dc:creator>
		<pubDate>Mon, 27 Jun 2011 19:45:59 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=13248#comment-144239</guid>
		<description><![CDATA[Hi Pinal,
With minimal operation I think we can achieve this with below code and it can handle multiple @ scenario
Code:

SELECT 
RIGHT(email,CHARINDEX(&#039;@&#039;,REVERSE(email))-1) AS Domain,
COUNT(*) AS [No] 
FROM @t 
WHERE len(ISNULL(email,&#039;&#039;)) &gt; 1
GROUP BY  RIGHT(email,CHARINDEX(&#039;@&#039;,REVERSE(email))-1)]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,<br />
With minimal operation I think we can achieve this with below code and it can handle multiple @ scenario<br />
Code:</p>
<p>SELECT<br />
RIGHT(email,CHARINDEX(&#8216;@&#8217;,REVERSE(email))-1) AS Domain,<br />
COUNT(*) AS [No]<br />
FROM @t<br />
WHERE len(ISNULL(email,&#8221;)) &gt; 1<br />
GROUP BY  RIGHT(email,CHARINDEX(&#8216;@&#8217;,REVERSE(email))-1)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Krishna</title>
		<link>http://blog.sqlauthority.com/2011/06/18/sql-server-selecting-domain-from-email-address/#comment-142430</link>
		<dc:creator><![CDATA[Krishna]]></dc:creator>
		<pubDate>Mon, 20 Jun 2011 10:30:26 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=13248#comment-142430</guid>
		<description><![CDATA[SELECT ISNULL(SUBSTRING(Email,CHARINDEX(&#039;@&#039;,isnull(email,&#039;&#039;)) + 1,LEN(Email) - CHARINDEX(&#039;@&#039;,isnull(email,&#039;&#039;))),&#039;&#039;),COUNT(*) as overallcount
FROM @t
WHERE ISNULL(Email,&#039;&#039;)  &#039;&#039;
GROUP BY 
	ISNULL(SUBSTRING(Email,CHARINDEX(&#039;@&#039;,isnull(email,&#039;&#039;)) + 1,LEN(Email) - CHARINDEX(&#039;@&#039;,isnull(email,&#039;&#039;))),&#039;&#039;)
ORDER BY 
	overallcount DESC]]></description>
		<content:encoded><![CDATA[<p>SELECT ISNULL(SUBSTRING(Email,CHARINDEX(&#8216;@&#8217;,isnull(email,&#8221;)) + 1,LEN(Email) &#8211; CHARINDEX(&#8216;@&#8217;,isnull(email,&#8221;))),&#8221;),COUNT(*) as overallcount<br />
FROM @t<br />
WHERE ISNULL(Email,&#8221;)  &#8221;<br />
GROUP BY<br />
	ISNULL(SUBSTRING(Email,CHARINDEX(&#8216;@&#8217;,isnull(email,&#8221;)) + 1,LEN(Email) &#8211; CHARINDEX(&#8216;@&#8217;,isnull(email,&#8221;))),&#8221;)<br />
ORDER BY<br />
	overallcount DESC</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vinay Kumar</title>
		<link>http://blog.sqlauthority.com/2011/06/18/sql-server-selecting-domain-from-email-address/#comment-142381</link>
		<dc:creator><![CDATA[Vinay Kumar]]></dc:creator>
		<pubDate>Mon, 20 Jun 2011 06:17:29 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=13248#comment-142381</guid>
		<description><![CDATA[select SUBSTRING(EmailAddress,PATINDEX(&#039;%@%&#039;,EmailAddress)+1,100),COUNT(1) from Person.Contact
 GROUP BY SUBSTRING(EmailAddress,PATINDEX(&#039;%@%&#039;,EmailAddress)+1,100)
ORDER BY 2 DESC

Try This query.]]></description>
		<content:encoded><![CDATA[<p>select SUBSTRING(EmailAddress,PATINDEX(&#8216;%@%&#8217;,EmailAddress)+1,100),COUNT(1) from Person.Contact<br />
 GROUP BY SUBSTRING(EmailAddress,PATINDEX(&#8216;%@%&#8217;,EmailAddress)+1,100)<br />
ORDER BY 2 DESC</p>
<p>Try This query.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James</title>
		<link>http://blog.sqlauthority.com/2011/06/18/sql-server-selecting-domain-from-email-address/#comment-141922</link>
		<dc:creator><![CDATA[James]]></dc:creator>
		<pubDate>Sat, 18 Jun 2011 16:53:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=13248#comment-141922</guid>
		<description><![CDATA[I have something like that. Which was separating the username and domain parts of the address. I am using it in a computed column. See below

(left([EMailAddress],charindex(&#039;@&#039;,[EMailAddress])-(1)))
and
(right([EMailAddress],len([EMailAddress])-charindex(&#039;@&#039;,[EMailAddress])))

However I was not able to solve a problem with it crashing when reading the table with invalid email&#039;s which did not contain an @ symbol.]]></description>
		<content:encoded><![CDATA[<p>I have something like that. Which was separating the username and domain parts of the address. I am using it in a computed column. See below</p>
<p>(left([EMailAddress],charindex(&#8216;@&#8217;,[EMailAddress])-(1)))<br />
and<br />
(right([EMailAddress],len([EMailAddress])-charindex(&#8216;@&#8217;,[EMailAddress])))</p>
<p>However I was not able to solve a problem with it crashing when reading the table with invalid email&#8217;s which did not contain an @ symbol.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason</title>
		<link>http://blog.sqlauthority.com/2011/06/18/sql-server-selecting-domain-from-email-address/#comment-141907</link>
		<dc:creator><![CDATA[Jason]]></dc:creator>
		<pubDate>Sat, 18 Jun 2011 15:28:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=13248#comment-141907</guid>
		<description><![CDATA[I would also guess that using &quot;WHERE LEN(email)  &gt; 0&quot; is not SARGable, and not using an index if it&#039;s available.]]></description>
		<content:encoded><![CDATA[<p>I would also guess that using &#8220;WHERE LEN(email)  &gt; 0&#8243; is not SARGable, and not using an index if it&#8217;s available.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason</title>
		<link>http://blog.sqlauthority.com/2011/06/18/sql-server-selecting-domain-from-email-address/#comment-141898</link>
		<dc:creator><![CDATA[Jason]]></dc:creator>
		<pubDate>Sat, 18 Jun 2011 14:54:59 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=13248#comment-141898</guid>
		<description><![CDATA[According to RFC&#039;s 5322 and 5321, a quoted string can be used to allow invalid characters... such that &quot;pinal@home&quot;@sqlauthority.com would be a valid email address.  However, it&#039;s rare to see a quoted string used for email.]]></description>
		<content:encoded><![CDATA[<p>According to RFC&#8217;s 5322 and 5321, a quoted string can be used to allow invalid characters&#8230; such that &#8220;pinal@home&#8221;@sqlauthority.com would be a valid email address.  However, it&#8217;s rare to see a quoted string used for email.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Manish Sharma</title>
		<link>http://blog.sqlauthority.com/2011/06/18/sql-server-selecting-domain-from-email-address/#comment-141872</link>
		<dc:creator><![CDATA[Manish Sharma]]></dc:creator>
		<pubDate>Sat, 18 Jun 2011 12:43:09 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=13248#comment-141872</guid>
		<description><![CDATA[Hi Pinal,

Recently I have used the same method for one of my shopping cart project. I was asked to show approx 50 characters for a product description followed by 4 dots and it should not cut last word. So I used the same method. here is my query 

SELECT productID, productName, LEFT(productDescription, CHARINDEX(&#039;&#039; &#039;&#039;, productDescription, 50))+&#039;&#039;....&#039;&#039; as productDescription, ....
FROM tbl_Products


Thanks]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,</p>
<p>Recently I have used the same method for one of my shopping cart project. I was asked to show approx 50 characters for a product description followed by 4 dots and it should not cut last word. So I used the same method. here is my query </p>
<p>SELECT productID, productName, LEFT(productDescription, CHARINDEX(&#8221; &#8221;, productDescription, 50))+&#8221;&#8230;.&#8221; as productDescription, &#8230;.<br />
FROM tbl_Products</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vishaldobariya</title>
		<link>http://blog.sqlauthority.com/2011/06/18/sql-server-selecting-domain-from-email-address/#comment-141849</link>
		<dc:creator><![CDATA[vishaldobariya]]></dc:creator>
		<pubDate>Sat, 18 Jun 2011 10:05:19 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=13248#comment-141849</guid>
		<description><![CDATA[good one]]></description>
		<content:encoded><![CDATA[<p>good one</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jatinkacha</title>
		<link>http://blog.sqlauthority.com/2011/06/18/sql-server-selecting-domain-from-email-address/#comment-141812</link>
		<dc:creator><![CDATA[jatinkacha]]></dc:creator>
		<pubDate>Sat, 18 Jun 2011 06:03:55 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=13248#comment-141812</guid>
		<description><![CDATA[Thanks for share. Good script]]></description>
		<content:encoded><![CDATA[<p>Thanks for share. Good script</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ashok</title>
		<link>http://blog.sqlauthority.com/2011/06/18/sql-server-selecting-domain-from-email-address/#comment-141802</link>
		<dc:creator><![CDATA[Ashok]]></dc:creator>
		<pubDate>Sat, 18 Jun 2011 05:10:49 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=13248#comment-141802</guid>
		<description><![CDATA[Hi;
Mr. Pinaldave 

It&#039;s Excellent   and  very much use full  


Thanks  a lot]]></description>
		<content:encoded><![CDATA[<p>Hi;<br />
Mr. Pinaldave </p>
<p>It&#8217;s Excellent   and  very much use full  </p>
<p>Thanks  a lot</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ashishrao</title>
		<link>http://blog.sqlauthority.com/2011/06/18/sql-server-selecting-domain-from-email-address/#comment-141800</link>
		<dc:creator><![CDATA[ashishrao]]></dc:creator>
		<pubDate>Sat, 18 Jun 2011 05:04:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=13248#comment-141800</guid>
		<description><![CDATA[select substring(emailid,charindex(&#039;@&#039;,emailid)+1,len(emailid)) as Domain,count(emailid) as EmailCount
from email
where len(emailid)&gt;0
group by substring(emailid,charindex(&#039;@&#039;,emailid)+1,len(emailid))
order by Emailcount desc]]></description>
		<content:encoded><![CDATA[<p>select substring(emailid,charindex(&#8216;@&#8217;,emailid)+1,len(emailid)) as Domain,count(emailid) as EmailCount<br />
from email<br />
where len(emailid)&gt;0<br />
group by substring(emailid,charindex(&#8216;@&#8217;,emailid)+1,len(emailid))<br />
order by Emailcount desc</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aneel Mehta</title>
		<link>http://blog.sqlauthority.com/2011/06/18/sql-server-selecting-domain-from-email-address/#comment-141799</link>
		<dc:creator><![CDATA[Aneel Mehta]]></dc:creator>
		<pubDate>Sat, 18 Jun 2011 05:02:58 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=13248#comment-141799</guid>
		<description><![CDATA[Cant we use &quot;substring&quot; instead if &quot;right&quot;   here ?
like 

select substring(Email  , CHARINDEX(&#039;@&#039;, Email )+ 1,len(Email)) Domain  ,
 count(Email ) EmailCount
from dbo.data 
where len(isnull(Email ,&#039;&#039;)) &gt; 0
group by substring(Email , CHARINDEX(&#039;@&#039;, Email )+ 1,len(Email))
order by Emailcount desc]]></description>
		<content:encoded><![CDATA[<p>Cant we use &#8220;substring&#8221; instead if &#8220;right&#8221;   here ?<br />
like </p>
<p>select substring(Email  , CHARINDEX(&#8216;@&#8217;, Email )+ 1,len(Email)) Domain  ,<br />
 count(Email ) EmailCount<br />
from dbo.data<br />
where len(isnull(Email ,&#8221;)) &gt; 0<br />
group by substring(Email , CHARINDEX(&#8216;@&#8217;, Email )+ 1,len(Email))<br />
order by Emailcount desc</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: praveen</title>
		<link>http://blog.sqlauthority.com/2011/06/18/sql-server-selecting-domain-from-email-address/#comment-141798</link>
		<dc:creator><![CDATA[praveen]]></dc:creator>
		<pubDate>Sat, 18 Jun 2011 05:02:41 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=13248#comment-141798</guid>
		<description><![CDATA[Thanks sir, good articles to learn]]></description>
		<content:encoded><![CDATA[<p>Thanks sir, good articles to learn</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: haile</title>
		<link>http://blog.sqlauthority.com/2011/06/18/sql-server-selecting-domain-from-email-address/#comment-141794</link>
		<dc:creator><![CDATA[haile]]></dc:creator>
		<pubDate>Sat, 18 Jun 2011 04:28:18 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=13248#comment-141794</guid>
		<description><![CDATA[you can also use the substring function to get the domain part of the email
substring(email, charindex(&#039;@&#039;, email) + 1, len(email))]]></description>
		<content:encoded><![CDATA[<p>you can also use the substring function to get the domain part of the email<br />
substring(email, charindex(&#8216;@&#8217;, email) + 1, len(email))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Suman Balguri</title>
		<link>http://blog.sqlauthority.com/2011/06/18/sql-server-selecting-domain-from-email-address/#comment-141775</link>
		<dc:creator><![CDATA[Suman Balguri]]></dc:creator>
		<pubDate>Sat, 18 Jun 2011 02:51:31 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=13248#comment-141775</guid>
		<description><![CDATA[SELECT RIGHT(Email, CHARINDEX(‘@’, REVERSE(email))-1) as Domain ,
COUNT(Email) as EmailCount
FROM dbo.email
WHERE LEN(Email) &gt; 0
GROUP BY RIGHT(Email, CHARINDEX(‘@’, REVERSE(email))-1)
ORDER BY EmailCount DESC]]></description>
		<content:encoded><![CDATA[<p>SELECT RIGHT(Email, CHARINDEX(‘@’, REVERSE(email))-1) as Domain ,<br />
COUNT(Email) as EmailCount<br />
FROM dbo.email<br />
WHERE LEN(Email) &gt; 0<br />
GROUP BY RIGHT(Email, CHARINDEX(‘@’, REVERSE(email))-1)<br />
ORDER BY EmailCount DESC</p>
]]></content:encoded>
	</item>
</channel>
</rss>
