You have an error in your SQL syntax; check the manual that corresponds to your MySQL

Posted by LuisEValencia on Stack Overflow See other posts from Stack Overflow or by LuisEValencia
Published on 2012-08-31T21:27:59Z Indexed on 2012/08/31 21:38 UTC
Read the original article Hit count: 115

Filed under:

I am trying to run a mysql query to find all occurences of a text. I have a syntax error but dont know where or how to fix it

I am using sqlyog to execute this script

DECLARE @url VARCHAR(255)

SET @url = '1720'

SELECT 'select * from ' + RTRIM(tbl.name) + ' where ' + 
          RTRIM(col.name) + ' like %' + RTRIM(@url) + '%'
FROM sysobjects tbl
INNER JOIN syscolumns col ON tbl.id = col.id 
AND col.xtype IN (167, 175, 231, 239) -- (n)char and (n)varchar, there may be others to include
AND col.length > 30 -- arbitrary min length into which you might store a URL
WHERE tbl.type = 'U'    -- user defined table

1 queries executed, 0 success, 1 errors, 0 warnings

Query: declare @url varchar(255) set @url = '1720' select 'select * from ' + rtrim(tbl.name) + ' where ' + rtrim(col.name) + ' like %' ...

Error Code: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'declare @url varchar(255)

© Stack Overflow or respective owner

Related posts about mysql