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 2005 Forums
 Transact-SQL (2005)
 Concatenate SQL

Author  Topic 

thatzlim
Starting Member

6 Posts

Posted - 2007-10-22 : 06:44:02
hi. i would like to create a sql string in my Stored Procedure.
the sql string should look like this:
Select * from User Where Name LIKE '%abc%'


where abc is stored in an alias @name

i wrote this:

declare @sql nvarchar(50)
set @sql = 'Select * from User Where Name LIKE '%' + @name + '%'


how can i put the Quote sign before and after the % sign?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-10-22 : 06:46:46
use two quote sign

set @sql = 'Select * from User Where Name LIKE ''%' + @name + '%'''



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

thatzlim
Starting Member

6 Posts

Posted - 2007-10-22 : 06:49:11
quote:
Originally posted by khtan

use two quote sign

set @sql = 'Select * from User Where Name LIKE ''%' + @name + '%'''



KH
[spoiler]Time is always against us[/spoiler]




thx a lot!!!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-10-22 : 06:58:38
quote:
Originally posted by thatzlim

hi. i would like to create a sql string in my Stored Procedure.
the sql string should look like this:
Select * from User Where Name LIKE '%abc%'


where abc is stored in an alias @name

i wrote this:

declare @sql nvarchar(50)
set @sql = 'Select * from User Where Name LIKE '%' + @name + '%'


how can i put the Quote sign before and after the % sign?


or

Select * from User Where Name LIKE '%' + @name + '%'


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -