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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 LIKE with @var

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-01-21 : 08:51:10
Martin Holm writes "Hi there..
How do i write a dynamic Stored Procedure with @var and LIKE.

I have tried:

CREATE PROCEDURE dbo.up_search_island
@islandName varchar(20)
AS
DECLARE @vSQL varchar(1000)
SELECT @vSQL = 'SELECT * FROM island_T WHERE island_name_VC LIKE %' + @islandName + '%'
EXECUTE (@vSQL)
GO

I dont understand whats wrong.
May the force be with you
/Martin"

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2003-01-21 : 09:02:50

create proc dbo.up_search_island
@islandName varchar(20)
as
select
*
from
island_T
where
island_name_VC like '%' + @islandName + '%'
go

 
(Or if you must use dynamic sql, you need to work on the quotes around your literals in you WHERE clause....)

Jay White
{0}

Edited by - Page47 on 01/21/2003 09:03:12
Go to Top of Page

ValterBorges
Master Smack Fu Yak Hacker

1429 Posts

Posted - 2003-01-21 : 09:06:39
LIKE ''%' + @islandName + '%'''

Go to Top of Page
   

- Advertisement -