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
 General SQL Server Forums
 New to SQL Server Programming
 SQL query LIKE with variable.

Author  Topic 

bluestar
Posting Yak Master

133 Posts

Posted - 2008-08-05 : 12:44:39
Hello

Can anyone please tell me how to use sql like query with variable.

when I am doing this
SELECT SystemElementID,SETitleText,SESummaryText
FROM SystemElement
where SESummaryText LIKE '%history%'

its executing fine.

But when I doing this
ALTER PROCEDURE [dbo].[sp_SystemSearch]

@text as Text
AS

BEGIN
SET NOCOUNT ON;


SELECT SystemElementID,SETitleText,SESummaryText
FROM SystemElement
where SESummaryText LIKE @text
END

I am not getting any result.
After executing it only shows table name and no result.

Thank You

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-05 : 12:50:39
may be this:-

ALTER PROCEDURE [dbo].[sp_SystemSearch]

@text as Text
AS

BEGIN
SET NOCOUNT ON;


SELECT SystemElementID,SETitleText,SESummaryText
FROM SystemElement
where SESummaryText LIKE '%' +@text + '%'
END
Go to Top of Page

bluestar
Posting Yak Master

133 Posts

Posted - 2008-08-05 : 13:01:19
Thanks a TONS!!!!
Go to Top of Page
   

- Advertisement -