1

I'm trying to do a practice question for my SQL class and I'm having lots of trouble getting my query to work properly, here's my code - can anyone help me?

  1. Write a stored procedure called LookUpCustomer that accepts any part of a Customers last name.
    Return all the customer attributes for those customers from the customer table.

Code:

Create Procedure LookUpCustomer 
    (@CustomerLastName varchar(30) = null)
as
    select CustomerLastName 
    from Customer
    where @CustomerLastName like ('_[A-Z]_')

I'm getting these results:

CustomerLastName:
Simpson,
Jones,
Forman,
smilie,
Lauper,
Marley,
Presely,
Clapton,
Johnson,
Douglas,
Leno,
Little,
Tyler,
McDonald,
Carlson,

but I need it so it takes any part of a customer last name, I don't know if this is working properly, thanks to all that help out!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
mike
  • 27
  • 6
  • 2
    Procedural code is **highly vendor-specific** - so please add a tag to specify whether you're using `mysql`, `postgresql`, `sql-server`, `oracle` or `db2` - or something else entirely. – marc_s Apr 01 '17 at 06:19

2 Answers2

0

Please try the following...

CREATE PROCEDURE LookUpCustomer ( @CustomerLastNamePart VARCHAR( 30 ) = NULL ) AS
    SELECT CustomerLastName
    FROM Customer
    WHERE CustomerLastName LIKE '%{@CustomerLastNamePart}%'

Further reading...

https://dev.mysql.com/doc/refman/5.7/en/string-comparison-functions.html

MySQL query String contains

If you have any questions or comments, then please feel free to post a Comment accordingly.

Community
  • 1
  • 1
toonice
  • 2,211
  • 1
  • 13
  • 20
0

Try : select CustomerLastName from Customer WHERE CustomerLastName LIKE '%' +@CustomerLastName+'%'

Anupam Singh
  • 1,158
  • 13
  • 25