Jigar Shah
Jigar Shah

Reputation: 175

Sql Query with Brackets

I am making a query to lists down all stored procedures which contains an insert statement for a table.

Query doesn't give result if '[' is used in like statement.

SELECT Name,OBJECT_DEFINITION(object_id) 
FROM   sys.procedures WHERE OBJECT_DEFINITION(object_id) LIKE '%[dbo].[TABLE]%'

Problem is with '[', but not able to get it solved.

Upvotes: 0

Views: 99

Answers (1)

Pieter Geerkens
Pieter Geerkens

Reputation: 11893

Try this:

SELECT Name,OBJECT_DEFINITION(object_id) 
FROM   sys.procedures WHERE OBJECT_DEFINITION(object_id) LIKE '%[[]dbo].[[]TABLE]%'

which escapes each instance of '[' by replacing it with '[[]'.

Upvotes: 1

Related Questions