Click here to Skip to main content
12,507,674 members (55,818 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: MySQL
HI

My problem is as follows. I have a table that has an "ID" field with id's that begin with "ST" and "#STA". I want to save the ID field in a variable and then "IF" it begins with "ST" i want to run a stored procedure else if it begins with "#STA" i want to run a different stored procedure. How do i accomplish this??

I tried to do it the following way:

@id := "either ST or #STA"

IF @id LIKE "#STA"
THEN
"DO SOMETHING"
END IF

Im a bit lost, can someone help?
Posted 7-Jan-13 7:21am
Ashy-G562
Comments
jibesh 7-Jan-13 13:46pm
   
Are you using a stored procedure?
Ashy-G 8-Jan-13 7:52am
   
yes

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

When using LIKE[^] is the situation you describe you need to use the '%' wildcard.
If a string should start with a particular pattern (in your case "#STA") add the wildcard '%' to the end of the pattern. The wildcard '%' stands for any string of zero or more characters.

So use
IF @id LIKE "#STA%"
and any string that begins with "#STA" would mean "DO SOMETHING" is executed.
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160927.1 | Last Updated 7 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100