Friday, February 24, 2012

"Like" Stored Procedure Help Needed

Jeff,

> where (((title like '@.SearchTerm%' or @.Searchterm IS NULL) or
> (Document like '@.SearchTerm%' or @.SearchTerm IS NUll))and
You are surrounding the variable name with apostrophes and this is not the
same as concatenating the value of the variable with the wildcard '%'.
'@.SearchTerm%' --> @.SearchTerm + '%'
Example:
declare @.s varchar(25)
set @.s = 'sql server'
select '@.s%', @.s + '%'
go
so your statement should be like:
...
where
(((title like @.SearchTerm + '%' or @.Searchterm IS NULL) or
(Document like @.SearchTerm + '%' or @.SearchTerm IS NUll))and
...
AMB
"Jeff" wrote:

> What is wrong with my Stored Procedure? The select Statement returns corr
ect
> results...why not the Stored Procedure?
>
> select *
> from tbldocument
> where (title like 'ros%') or
> (document like 'asdf%') and
> Submitterid = '1'
>
> Create Procedure PROCEDURE SearchDocument
> (
> @.SearchTerm char (200) = NULL,
> @.SubmitterID int = null
> )
> as
>
> SELECT dbo.tblDocument.DocumentID,
> dbo.tblDocument.Title,
> dbo.tblSubmitter.SubmitterName
> FROM dbo.tblDocument join dbo.tblSubmitter
> on (tbldocument.submitterid = tblsubmitter.submitterid)
> where (((title like '@.SearchTerm%' or @.Searchterm IS NULL) or
> (Document like '@.SearchTerm%' or @.SearchTerm IS NUll))and
> (dbo.tblDocument.SubmitterID = @.submitterID or @.SubmitterID is null)
)
>Me have so much to learn!!
Thanks!!
"Alejandro Mesa" wrote:
> Jeff,
>
> You are surrounding the variable name with apostrophes and this is not the
> same as concatenating the value of the variable with the wildcard '%'.
> '@.SearchTerm%' --> @.SearchTerm + '%'
> Example:
> declare @.s varchar(25)
> set @.s = 'sql server'
> select '@.s%', @.s + '%'
> go
> so your statement should be like:
> ...
> where
> (((title like @.SearchTerm + '%' or @.Searchterm IS NULL) or
> (Document like @.SearchTerm + '%' or @.SearchTerm IS NUll))and
> ...
>
> AMB
> "Jeff" wrote:
>

No comments:

Post a Comment