I have another problem with a stored procedure. What I am tryin to do is if the @discipline variable is not empty append my search variable, please see below:
The problem that I have got is in the if statement, it returns the following error:
Server: Msg 105, Level 15, State 1, Procedure spSearchComm, Line 8
Unclosed quotation mark before the character string
@strQuery .= and commDisp= + @discipline +
end if
exec (@strQuery)
.
Server: Msg 170, Level 15, State 1, Procedure spSearchComm, Line 8
Line 8: Incorrect syntax near
@strQuery .= and commDisp= + @discipline +
end if
exec (@strQuery)
.
Is anyone able to point out where I have gone wrong?
Thanks inadvance
Simon
Code:
CREATE PROCEDURE [dbo].[spSearchComm] @project as varchar(50), @search as varchar(255),@discipline as varchar(50)
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 +
if @discipline != "
@strQuery .= and commDisp= + @discipline +
end if
exec (@strQuery)
GO
The problem that I have got is in the if statement, it returns the following error:
Server: Msg 105, Level 15, State 1, Procedure spSearchComm, Line 8
Unclosed quotation mark before the character string
@strQuery .= and commDisp= + @discipline +
end if
exec (@strQuery)
.
Server: Msg 170, Level 15, State 1, Procedure spSearchComm, Line 8
Line 8: Incorrect syntax near
@strQuery .= and commDisp= + @discipline +
end if
exec (@strQuery)
.
Is anyone able to point out where I have gone wrong?
Thanks inadvance
Simon
Last edited by a moderator: