check multiple condition qualified or not in sql srver

harinathu 6 Reputation points
2022-06-21T06:25:14.517+00:00

Hi I have one dobut in sql server .
how to check 2 conditions qualified or not in emailid
first check @ symbole is available or not if its available after @ next .(dot) symbole is availablero not
if both conditions satisfied then reterive those records .
CREATE TABLE [dbo].empdetails
INSERT [dbo].[empdetails] ([empid], [empmailid], [sal]) VALUES (1, N'abc.g@Stuff .com', 100)
INSERT [dbo].[empdetails] ([empid], [empmailid], [sal]) VALUES (2, N'hari.@Stuff ', 200)
INSERT [dbo].[empdetails] ([empid], [empmailid], [sal]) VALUES (3, N'vani@Stuff .com', 300)
INSERT [dbo].[empdetails] ([empid], [empmailid], [sal]) VALUES (4, N'ravi.kishor@réalisations .in', 400)
INSERT [dbo].[empdetails] ([empid], [empmailid], [sal]) VALUES (5, N'har.pan@Stuff .com', 500)
INSERT [dbo].[empdetails] ([empid], [empmailid], [sal]) VALUES (6, N'hanithanu.ra', 600)

based on above data I want output like below :
empid |empmailid |sal
1 |abc.g@Stuff .com |100
3 |vani@Stuff .com |300
4 |ravi.kishor@réalisations .in|400
5 |har.pan@Stuff .com |500
I have tried like below .
SELECT [empid]
,[empmailid]
,[sal]
FROM [test123].[dbo].[empdetails]
where empmailid like '%@%' and empmailid like'.'
above query not given expected result .
please tell me how to write query to achive this task in sql server

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,437 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,689 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Olaf Helper 45,881 Reputation points
    2022-06-21T07:14:16.523+00:00

    Just use one combined search string, like

    select *  
    from yourTable  
    where empmailid like '%@%.%'  
    
    1 person found this answer helpful.
    0 comments No comments

  2. Bert Zhou-msft 3,436 Reputation points
    2022-06-21T07:14:33.327+00:00

    Try this:

     SELECT [empid]  
    ,[empmailid]  
    ,[sal]  
    FROM [dbo].[empdetails]  
    where empmailid like '%@%' and charindex('.', empmailid,(charindex('@', empmailid, 1)))>0  
    

    213255-image.png

    Bert Zhou

    1 person found this answer helpful.
    0 comments No comments

  3. Tom Phillips 17,741 Reputation points
    2022-06-23T14:01:08.5+00:00
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.