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
 SQL Server Development (2000)
 LIKE in a dynamic sql

Author  Topic 

skillile
Posting Yak Master

208 Posts

Posted - 2002-02-14 : 09:02:28
declare @search varchar(20)
declare @sql varchar(2000)
set @search='a'


set @sql='select fname from tbluser where fname'

--print @sql
exec(@sql)

--how do I set this to dynamic sql
select fname from tbluser where fname like '%' + @search + '%'

--can I somehow set the @search to be = to % when no value is requested to
--return all instead of a filtered view
--ie

select fname from tbluser where fname like '%' + '%' + '%'

slow down to move faster...

lfmn
Posting Yak Master

141 Posts

Posted - 2002-02-14 : 10:05:10
use pubs
declare @search varchar(20)
declare @sql varchar(2000)
set @search='w'


set @sql='select au_fname from authors where au_lname like ''%' + @search + '%'''

print @sql
exec(@sql)

cursors are like hammers - sometimes you have to use them, but watch your thumb!
Go to Top of Page
   

- Advertisement -