Search code examples
sql-serversql-server-2000

How to execute sql string using SQL Server 2000


I have a sql string that i would like to execute it in SQL Server 2000

Example:

DECLARE @CodeNameString VARCHAR(1000)
SET @CodeNameString = '%123% OR name LIKE %456% OR name LIKE %789%'
SELECT * FROM atable WHERE name LIKE @CodeNameString

Of course the above would be a lot easier in SQL 2008 but unfortunately i don't have that option...:

SET @CodeNameString = '"123" OR "456" OR "789"'
SELECT * FROM atable WHERE CONTAINS(name, @CodeNameString)

Is that possible?


Solution

  • I believe Sql 2000 also had dynamic Sql capabilities, in which case you can execute the whole query dynamically :

    EXEC(N'SELECT * FROM atable WHERE name LIKE ''%123%'' 
           OR name LIKE ''%456%'' OR name LIKE ''%789%''')