Reputation: 1076
I am trying this code
CREATE TABLE #t
(
nam Varchar(100)
)
INSERT INTO #t(nam)VALUES('abc[]def')
SELECT * FROM #t Where Quotename(nam) like Quotename('abc[]def')
drop table #t
and not giving me any result.... Am I missing something?
Upvotes: 1
Views: 451
Reputation: 4585
CREATE TABLE #t
(
nam Varchar(100)
);
INSERT INTO #t(nam)VALUES('abc[]def');
SELECT * FROM #t Where Quotename(nam) = Quotename('abc[]def');
drop table #t;
Its not returning anything because Brackets [ ]
are know as Wildcard alphabets with LIKE
.
The set of characters specified between brackets wildcard which will match any one characters in the specified position (the location of the wildcard).
http://msdn.microsoft.com/en-us/library/ms179859.aspx
Please open the link and search the following text.
Using the [ ] wildcard characters
Upvotes: 1
Reputation: 138980
You don't need quotename you need escape
CREATE TABLE #t
(
nam VARCHAR(100)
)
INSERT INTO #t(nam) VALUES('abc[]def')
SELECT *
FROM #t
WHERE nam LIKE 'abc\[]def' ESCAPE '\'
DROP TABLE #t
Upvotes: 1