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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Like Condition

Status
Not open for further replies.

dbljackson

Programmer
Joined
Feb 8, 2001
Messages
8
Location
US
I would like to pass a parameter to a stored procedure thats used in a like condition of the where clause.

Example:

Select all customer that start with "A"

Declare @Cust_no as char(4)

Select *
from customer
where customer_number like @Cust_no

Not having any luck with this. I have passed "A%". SP always
returns Null. Any comments appreciated.

TIA
 
You will need to enclose the string in quotes or pass the string enclode in single quotes:

DECLARE @strSql VARCHAR(255)

SELECT @strSql = 'Select *
from customer
where customer_number like ''' + @Cust_no + '''

execute (@strSql)

The actual string you need is:

Select *
from customer
where customer_number like 'A%'

Hope this helps,

Chris Dukes

 
Thanks Chris.

Double qoutes worked.

'' + @Cust_no + ''

dj
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top