Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 syntax problem

Author  Topic 

akpaga
Constraint Violating Yak Guru

331 Posts

Posted - 2008-04-15 : 09:41:38
This my stored procedure

alter PROCEDURE t
@search varchar(200)
AS

SET NOCOUNT ON
declare @str as varchar(1028)
declare @str2 as varchar(128)
declare @i as int
declare @count as int

set @str2 = 'PARSENAME(replace(replace(replace(rtrim(ltrim(' + replace(@search,'''','''''') + ')),'''' '''',''''<>''''),''''><'''',''''''''),''''<>'''','''' ''''),'
set @str = ' where merchant_name LIKE ''''%'''' + ' + @str2 + '1) + ''''%'''' '

set @i = 1
SET @Count = (select dbo.WordCount(@search))

while @i <@count
begin

set @i =@i +1
set @str = @str + 'AND merchant_name LIKE ''''%'''' + ' + @str2 + cast(@i as varchar) + ') + ''''%'''' '

exec('select * from merchant ' + @str)
end

GO

when i exec the above stored procedure as this
--- exec t 'taj''s residency'
its showing error ---- Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near ''.

what is wrong


thanks in advance

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-15 : 09:48:14
If you instead of executing the statement, just do a

PRINT 'select * from merchant ' + @str

and copy the output, what do you see that is wrong?
When you try to run the copied output which error do you get.

Now fix them.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

akpaga
Constraint Violating Yak Guru

331 Posts

Posted - 2008-04-15 : 13:31:14
thanks peso
Go to Top of Page
   

- Advertisement -