SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Find string
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

rocknpop
Posting Yak Master

184 Posts

Posted - 11/29/2013 :  03:29:16  Show Profile  Reply with Quote

DECLARE @TBL TABLE (NAME VARCHAR(100))

INSERT INTO @TBL VALUES('A.XYZ'),('B.PQR'),('C.JPG'),('A.ABC')

I want to find only *.XYZ,*.PQR,*.JPG and nothing else. Can we write a single regular expression to return this?

Thanks

--------------------
Rock n Roll with SQL

khtan
In (Som, Ni, Yak)

Singapore
17598 Posts

Posted - 11/29/2013 :  03:34:15  Show Profile  Reply with Quote
where	right(NAME, 3) in ('XYZ', 'PQR', 'JPG')



KH
Time is always against us

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 11/29/2013 :  04:35:47  Show Profile  Reply with Quote
SELECT * FROM @TBL WHERE NAME LIKE '%[.XYZ|.PQR|.JPG]'


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

rocknpop
Posting Yak Master

184 Posts

Posted - 11/29/2013 :  05:16:46  Show Profile  Reply with Quote
Thanks to both for the solution.

--------------------
Rock n Roll with SQL
Go to Top of Page

rocknpop
Posting Yak Master

184 Posts

Posted - 11/29/2013 :  08:20:22  Show Profile  Reply with Quote
khtan: What if the length of the extension is 4, say .jpeg?

Visakh:

DECLARE @TBL TABLE (NAME VARCHAR(100))

INSERT INTO @TBL VALUES('A.xyz'),('B.pqr'),('C.jpg'),('A.ABC'),('A.jpeg')

SELECT * FROM @TBL WHERE NAME LIKE '%[.XYZ|.PQR|.JPEG]'

It returns .jpg too but it should not. I thought this was a generic solution, anyway we can include just any extension.

Thanks

--------------------
Rock n Roll with SQL
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 11/30/2013 :  02:05:42  Show Profile  Reply with Quote


DECLARE @TBL TABLE (NAME VARCHAR(100))

INSERT INTO @TBL VALUES('A.xyz'),('B.pqr'),('C.jpg'),('A.ABC'),('A.jpeg'),('A.wxyz')

SELECT t.* FROM @TBL t
CROSS APPLY (VALUES ('.XYZ'),('.PQR'),('.JPEG'))t1(pat)
WHERE NAME LIKE '%' + pat


output
-----------
NAME
-----------
A.xyz
B.pqr
A.jpeg



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

rocknpop
Posting Yak Master

184 Posts

Posted - 11/30/2013 :  10:27:44  Show Profile  Reply with Quote
perfect, thank you.

--------------------
Rock n Roll with SQL
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 12/01/2013 :  03:58:59  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000