473,407 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

syntax to pass parameter in like operator using stored procedure

Hi,

i'm using mysql database, i don't know syntax how to pass the parameter in like operator inside the stored procedure, i want to select the store number related to textbox input number given by user, Eg: if they type "3" we have to select which stores starts with "3", i got syntax error when executing the following stored procedure, please correct this sp and solve my problem
Advanced thanks for any reply.

CREATE PROCEDURE HD_SELECT_STORES(IN STORENUM INT)
BEGIN
select storeno from hd_stores_login where storeno like '"STORENUM"%';
END;

Thanks.
Jan 25 '07 #1
6 42709
Plz try this

CREATE PROCEDURE HD_SELECT_STORES
@STORENUM int
as
BEGIN
select storeno from hd_stores_login where storeno like @STORENUM;
END;

while Executing this stored procedure:

EXECUTE HD_SELECT_STORES 'Value%'


You can pass the wildcard while you execute the stored procedure, but u cannot give wildcard while creating it. So add the wildcard with the data you pass the parameter value.
Oct 4 '07 #2
[quote=sjsaran12]

Plz try this, Better Solution

CREATE PROCEDURE HD_SELECT_STORES
@STORENUM int
as
BEGIN
select storeno from hd_stores_login where storeno like '%'+@STORENUM+'%';
END;
Nov 14 '07 #3
sig0
1
Try LIKE CONCAT(STORENUM, '%')
Jul 9 '09 #4
SLauren
60
CREATE PROCEDURE HD_SELECT_STORES(IN STORENUM INT)
BEGIN
SET @pattern = CONCAT('%',STORENUM,'%');
SET @sql = 'select storeno from hd_stores_login where storeno like ?';
PREPARE stmt_name FROM @sql;
EXECUTE stmt_name USING @pattern;
DEALLOCATE PREPARE stmt_name ;

END;

Hope this could help.

Thanks,
Lauren
Jul 10 '09 #5
In case needing to pass more than one parameter:
/*** courtesy of Lauren's code **/

Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE HD_SELECT_STORES(IN STORENAME TEXT, IN STORENUM INT )
  2. BEGIN
  3. SET @pattern1 = CONCAT('%',STORENAME,'%');
  4. SET @pattern2 = STORENUM;
  5. SET @sql = 'select storeno from hd_stores_login where storename like ? AND stroreno = ?';
  6. PREPARE stmt_name FROM @sql;
  7. EXECUTE stmt_name USING @pattern1, @pattern2;
  8. DEALLOCATE PREPARE stmt_name ;
  9.  
  10. END;
  11.  
Cheers
Francis
Oct 8 '10 #6
Use the LEFT SQL function to get a number of characters on the left of the parameter. How many characters? you're wondering. I say all the characters. How so? Use the LEN SQL function to get the length of the parameter.


Example:
Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE dbo.OvertimeSearchName
  2.  
  3.     (
  4.  
  5.     @LastName nchar(200)
  6.     )
  7.  
  8. AS
  9.  
  10. BEGIN
  11. SELECT  EmployeeNumber,FirstName + ' ' + LastName as FullName
  12. FROM Employee 
  13. /* Pay attention here */
  14. WHERE    LastName like (left(@LastName,LEN(@LastName)))+'%' ;
  15.  
  16. END
  17.  
  18. --exec dbo.OvertimeSearchName '%Thakwalakwa%'
  19.  
  20.  
  21. RETURN
  22.  
Nov 17 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: sarith sutha | last post by:
Hi Need a help on the above topic, how to pass a java object as parameter to the java stored procedure .Code snippets will be greatly appreciated , i came across udf/udts etc but still not able...
3
by: Foehammer | last post by:
Hey, I'm writing some automated unit tests for a database app. The app creates a database via script. I'm developing the system in a test-driven manner and need a way to determine if a parameter...
2
by: Godzilla | last post by:
Dear all, I have a challenge in hand and am not too sure how to accomplish this using stored procedure. I have a table containing about 3 fields, but I need to reorder/renumber a field value...
1
hariharanmca
by: hariharanmca | last post by:
How to Shift or Copy Data from Sqlserver to MS Access using Stored procedure I am passing the clint MS Access file path in that i want to insert or update data in that MS Access file using...
0
by: Srireddy | last post by:
Hi all, I am trying to read an xml using stored procedure and upload it in to the DB. I am using DB2 v8.0. can anyone help me complete my assignment... Thanks in advance..
1
by: madhuparimi | last post by:
I am working on jasper reports.First i want to know how to generate a ireport using stored procedure. Can u please help me out and tell me how to generate an ireport using stored procedure
0
Saii
by: Saii | last post by:
How can we pass a perl array to stored procedure in Oracle. The parameter I am using in Oracle is type of table of varchar(500). I am using the system command in perl to execute the procedure ...
2
by: qwedster | last post by:
Folk! How to programattically check if null value exists in database table (using stored procedure)? I know it's possble in the Query Analyzer (see last SQL query batch statements)? But how...
2
by: hemantc87 | last post by:
i have created this function with a parameter offset and i want to access the database using stored procedure but the code and stored procedure i have written below is not working...what is the right...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.