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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 help with query

Author  Topic 

mike123
Master Smack Fu Yak Hacker

1462 Posts

Posted - 2009-02-17 : 03:05:35
Hi,

I have a table with 2 fields

tblUsers

nameOnline
emailAddress

I am looking to select all record from the table where there is a specific relationship between the "nameOnline" and "emailAddress" columns

1.) The username is the same as the email address before the @ symbol

2.) 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
Go to Top of Page

sridhar.dbe
Starting Member

34 Posts

Posted - 2009-02-17 : 03:37:14
Is this what you want

with t1 as
(
select 'sri_12iv' as 'uname','sri_12iv@fdf' as 'eaddr' union all
select 'kala_12bk' as 'uname','kala_12bk@fdf' as 'eaddr' union all
select 'padu_mj' as 'uname','padu_mj@fdf' as 'eaddr' union all
select '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]'

Go to Top of Page

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 fields

tblUsers

nameOnline
emailAddress

I am looking to select all record from the table where there is a specific relationship between the "nameOnline" and "emailAddress" columns

1.) The username is the same as the email address before the @ symbol

2.) 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 is

select * 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]'
Go to Top of Page
   

- Advertisement -