August 13, 2013 at 11:49 pm
Hi,
I want to display list of tables , which having "_" in the part of table name?
Thanks.
RR
August 14, 2013 at 12:48 am
select * from sysobjects where xtype='U' and name like '%_%'
August 14, 2013 at 1:12 am
laurie-789651 (8/14/2013)
select * from sysobjects where xtype='U' and name like '%_%'
That won't work because "_" is itself a wildcard character. Look up escape characters in Books Online.
John
August 14, 2013 at 1:26 am
Good point.
How about
select * from sysobjects where xtype='U' and name like '%[_]%
or
select * from sysobjects where xtype='U' and name like '%[_][_]%
for two underlines..
August 14, 2013 at 1:31 am
That seems to work... as long as you remember to close your quotes!
By the way, sysobjects is there for backward compatibility only. You should use sys.objects, sys.tables or INFORMATION_SCHEMA.TABLES instead.
John
August 14, 2013 at 1:34 am
Thanks Laurie...
it is working fine....
August 14, 2013 at 6:23 am
you can also try using ESCAPE -
SELECT s.name
FROM sys.objects s
WHERE
s.type= 'U'
AND s.name LIKE '%!_%' ESCAPE '!'
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply