Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with LIKE in Stored Procedures 1

Status
Not open for further replies.

thelobe

Programmer
Aug 18, 2004
9
ZA
Can anybody please tell me what syntax to use when using the LIKE statement in Stored Procedures. This is my code, which doesnt work :(

Code:
CREATE PROCEDURE dbo.Test

@STR_IRC_DESC varchar(50) = 'b'

AS

SELECT * FROM TBL_IRCS WHERE IRC_DESCRIPTION LIKE % @STR_IRC_DESC %

GO

Please help
Thanks
 
Is the IRC_DESCRIPTION a string? if so do you need it to be:

WHERE IRC_DESCRIPTION LIKE '%@STR_IRC_DESC%'
 
CREATE PROCEDURE dbo.Test

@STR_IRC_DESC varchar(50) = 'b'

AS

SELECT * FROM TBL_IRCS WHERE IRC_DESCRIPTION LIKE ('%'+@STR_IRC_DESC+'%')

GO

DBomrrsm
 
Silly me! of course - I keep doing the same thing in all my SPs which explains why none of them work very well :)
 
Just remember only use like with a wildcard in the first character if you absolutely have to. Using it means that the indexes can't be used and it will slow things down considerably.

Questions about posting. See faq183-874
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top