SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 syntax problem
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

akpaga
Constraint Violating Yak Guru

USA
311 Posts

Posted - 04/15/2008 :  09:41:38  Show Profile  Reply with Quote
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

Sweden
30175 Posts

Posted - 04/15/2008 :  09:48:14  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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

USA
311 Posts

Posted - 04/15/2008 :  13:31:14  Show Profile  Reply with Quote
thanks peso
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.16 seconds. Powered By: Snitz Forums 2000