forum

home / developersection / forums / how to drops special characters object_id in where clause

How to drops special characters OBJECT_ID in WHERE clause

Samuel Fernandes 1904 21-Jan-2015

I'm using the query below to identify databases for a drop-down list; it works fine, as long as the DatabaseName does not have any special characters (such as periods, commas, etc), but of course, we do want to include those. Now, when I run the Select statement by itself, it returns all of the tables correctly, but when I add in the WHERE clause, it loses the tables with punctuation in the name. I'm sure that I have a mistake in OBJECT_ID, but I just can't figure it out.

SELECT [name] AS DatabaseName FROM sys.databases

WHERE OBJECT_ID ([name] + N'.[dbo].[tblInfo]', N'U') IS NOT NULL

ORDER BY DatabaseName ASC


Updated on 21-Jan-2015
Can you answer this question?

Answer

1 Answers

Liked By