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.
| Author |
Topic |
|
mike123
Master Smack Fu Yak Hacker
1462 Posts |
Posted - 2009-02-17 : 03:05:35
|
| Hi,I have a table with 2 fieldstblUsersnameOnlineemailAddressI am looking to select all record from the table where there is a specific relationship between the "nameOnline" and "emailAddress" columns1.) The username is the same as the email address before the @ symbol2.) the last 5 characters of the username are "_" + (two numbers) + (two letters)Not exactly sure how to approach this, but any help is greatly appreciated !! thanks once again :)mike123 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-02-17 : 03:19:51
|
| can u post some sample data & required output |
 |
|
|
sridhar.dbe
Starting Member
34 Posts |
Posted - 2009-02-17 : 03:37:14
|
| Is this what you wantwith t1 as(select 'sri_12iv' as 'uname','sri_12iv@fdf' as 'eaddr' union allselect 'kala_12bk' as 'uname','kala_12bk@fdf' as 'eaddr' union allselect 'padu_mj' as 'uname','padu_mj@fdf' as 'eaddr' union allselect 'nag_sp' as 'uname','nag_p@gdf')select uname,eaddr from t1 where uname=left(eaddr,charindex('@',eaddr)-1)and uname like '%_[0-9][0-9][a-z][a-z]' |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-02-17 : 08:50:41
|
quote: Originally posted by mike123 Hi,I have a table with 2 fieldstblUsersnameOnlineemailAddressI am looking to select all record from the table where there is a specific relationship between the "nameOnline" and "emailAddress" columns1.) The username is the same as the email address before the @ symbol2.) the last 5 characters of the username are "_" + (two numbers) + (two letters)Not exactly sure how to approach this, but any help is greatly appreciated !! thanks once again :)mike123
seems like what you want isselect * from table where nameOnline=stuff(emailAddress ,charindex('@',emailAddress),len(emailAddress)-charindex('@',emailAddress)+1,'')and right(nameOnline,5) like '%_[0-9][0-9][A-Za-z][A-Za-z]' |
 |
|
|
|
|
|
|
|