Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 select email string

Author  Topic 

eugz
Posting Yak Master

210 Posts

Posted - 2012-01-05 : 10:43:41
Hi All.

I keep in column ContactInfo phone number and email address. How to select string with @ character by condition in select statement?

Thanks.

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-05 : 10:50:14
my usb esp port is clogged..please post Sample Data

Also, you should normalize your data into separate tables

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-05 : 11:01:10
do you have some delimiter between phone number and email values at least?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

eugz
Posting Yak Master

210 Posts

Posted - 2012-01-05 : 11:04:29
Phone number is number string. Email has @ character.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-05 : 11:08:30
who told?
its valid to have email address like 123somename@somedomain.com

so merging with phonenumber 12342345345 without any delimiter it will become

12342345345123somename@somedomain.com

then question is how would you identify which part is phone number and which is email

also phone number can come with or without code so you cant rely upon number of digits too


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-05 : 11:46:51
Please post some sample data that YOU have

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

eugz
Posting Yak Master

210 Posts

Posted - 2012-01-05 : 14:51:25
ID | ContactInfo
----+-------------------
2 1111111111
4 22222
5 sa@dsa.org
6 1591234564
7 hgfh@kjh.com
8 33333
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-05 : 14:57:37
SELECT * FROM myTable WHERE ContactInfo LIKE '%@%';


And Create a View for email

CREATE VIEW ContactEmail
AS
SELECT * FROM myTable WHERE ContactInfo LIKE '%@%';

And a View for Phones

CREATE VIEW ContactPhone
AS
SELECT * FROM myTable WHERE ContactInfo NOT LIKE '%@%';
Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

eugz
Posting Yak Master

210 Posts

Posted - 2012-01-05 : 16:56:59
Thanks.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-06 : 13:54:50
i didnt understand why you're storing different attributes inside same field. why not make field generic and have another field to indicate the type like 1= email, 2= phonenumber, 3=fax etc
you can even have a different type table to store master entries for contact type and use its id as foreign key in your table to increase flexibility and scalability

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-06 : 14:11:51
quote:
Originally posted by visakh16

i didnt understand why you're storing different attributes inside same field. why not make field generic and have another field to indicate the type like 1= email, 2= phonenumber, 3=fax etc
you can even have a different type table to store master entries for contact type and use its id as foreign key in your table to increase flexibility and scalability

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/





Or why not normalize the data in to separate tables?


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-06 : 14:14:05
Even thats an option so long as you dont have too many contacttypes and they wont have too many NULL values in which case you've to make them Sparse column

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-06 : 14:19:30
null values?

0 ==> M???

Why nulls?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-07 : 02:32:42
In case all persons wont have all contactinfo types most of columns will have NULL values

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -