lidds Posted December 4, 2006 Posted December 4, 2006 Could someone please help, I have been trying to spot the problem but I can't seem to see the problem. CREATE PROCEDURE [dbo].[spSearchComm] @project as varchar(50), @search as varchar(255) AS declare @strQuery varchar(8000) declare @strOrig varchar(3) set @strOrig = 'Yes' set @strQuery = 'SELECT * FROM commentsTbl WHERE projName=' + @project + ' and original=' + @strOrig + ' and commtitle like ' + @search + ' or commDesc like ' + @search + ' or commAction like ' + @search exec (@strQuery) GO [code] It is giving the following error but I everything things to be fine: Incorrect syntax near the keyword 'or' Thanks Simon Quote
MrPaul Posted December 4, 2006 Posted December 4, 2006 Quote varchars The above create procedure query executes fine so I assume you're getting the error when you actually execute the procedure. Perhaps you should place quotes around the varchar parameters like so: CREATE PROCEDURE [dbo].[spSearchComm] @project as varchar(50), @search as varchar(255) AS declare @strQuery varchar(8000) declare @strOrig varchar(3) set @strOrig = 'Yes' set @strQuery = 'SELECT * FROM commentsTbl WHERE projName=''' + @project + ''' and original=''' + @strOrig + ''' and commtitle like ''' + @search + ''' or commDesc like ''' + @search + ''' or commAction like ''' + @search + '''' exec (@strQuery) GO Good luck :cool: Quote Never trouble another for what you can do for yourself.
Administrators PlausiblyDamp Posted December 5, 2006 Administrators Posted December 5, 2006 If you are using a stored proc and only passing in a couple of parameters you shouldn't be needing to concatenate strings anyway. Try something like CREATE PROCEDURE [dbo].[spSearchComm] @project as varchar(50), @search as varchar(255) AS declare @strOrig varchar(3) set @strOrig = 'Yes' SELECT * FROM commentsTbl WHERE projName= @project and original= @strOrig and commtitle like @search or commDesc like @search or commAction like @search Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.