Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What is the proper syntax for thsi sql:variable?

0 views
Skip to first unread message

laredotornado

unread,
Sep 2, 2010, 4:38:50 PM9/2/10
to
Hi,

I'm using SQL Server 2005. I have

DECLARE @keyword varchar(4096);
SET @keyword = LOWER('abc');
SELECT DISTINCT
...
OR (vo.address1 LIKE
sql:variable("@keyword"))

but I'm getting a SQL server error on the line containing
"sql:variable" -- Incorrect syntax near 'sql' . Any ideas how to
properly write the "LIKE" clause using the sql declared variable?

Thanks, - Dave

Erland Sommarskog

unread,
Sep 2, 2010, 6:05:14 PM9/2/10
to
sql:variable is something you use in XQuery, but this is plain T-SQL.

Thus:

vo.address1 LIKE @keyword

or

vo.address1 LIKE '%' + @keyword + '%'

if you always want to add the wildcards.


--
Erland Sommarskog, SQL Server MVP, esq...@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

0 new messages