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
 using LIKE in the parameter

Author  Topic 

SQLBoy14
Yak Posting Veteran

70 Posts

Posted - 2014-03-10 : 14:20:09
Hi all,

I have a parameter @CustInd from a Column with varchar(4) data format called Customer_Index. Now if I want to let the users to input the value (for example) '%FFDS%' (FFDS is one of the values from Customer_Index) to get the output, how do I write it in where clause?

Thank you all

SQLBoy

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-03-10 : 14:34:38
WHERE Column1 LIKE @var1

Or:

WHERE Column1 LIKE '%' + @var1 + '%'

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

SQLBoy14
Yak Posting Veteran

70 Posts

Posted - 2014-03-10 : 14:40:02
Thank you Tara. I will test it and let you know.

SQLBoy
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2014-03-11 : 02:46:31
If using LIKE - beware of index scans and the potential impact that may have on the response time of a query

Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page

SQLBoy14
Yak Posting Veteran

70 Posts

Posted - 2014-03-11 : 14:44:08
Hi Tara. It is working. Thank you.

Hi Jack, thanks for the update.

SQLBoy
Go to Top of Page
   

- Advertisement -