October 30, 2008 at 12:39 pm
hi,
i m new to sql.
can any one brief the function of the below query and how it works
select * from tab
where patindex('%@friends1.com',email)>0
October 30, 2008 at 12:51 pm
The query you provide should return all rows in tab where '@friends1.com' are the final characters in the email column. If you have any non-blank characters after that string those rows will be eliminated. For example try this:
Declare @tab table (id int identity(1,1), char_email char(50), varchar_email varchar(50), nvarchar_email nvarchar(50))
Insert Into @tab
(
char_email,
varchar_email,
nvarchar_email
)
Select
'jack@friends1.com ',
'jack@friends1.com ',
'jack@friends1.com '
Union All
Select
'jack@friends1.com',
'jack@friends1.com',
'jack@friends1.com '
Union All
Select
'jack@friends1.com1',
'jack@friends1.com a',
'jack@friends1.com c'
Select
char_email,
patindex('%@friends1.com',char_email),
varchar_email,
patindex('%@friends1.com',varchar_email),
nvarchar_email,
patindex('%@friends1.com',nvarchar_email)
From
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
October 30, 2008 at 12:53 pm
Jack beat me to it, but you can also learn more about the patindex function in BOL (Books On-Line).
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply