Click here to Skip to main content
Rate this: bad
good
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-G522
Comments
jibesh at 7-Jan-13 13:46pm
   
Are you using a stored procedure?
Ashy-G at 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
0 Sergey Alexandrovich Kryukov 786
1 OriginalGriff 345
2 CPallini 160
3 PIEBALDconsult 150
4 Magic Wonder 131
0 OriginalGriff 5,705
1 Sergey Alexandrovich Kryukov 4,763
2 CPallini 4,570
3 George Jonsson 3,142
4 Gihan Liyanage 2,450


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 7 Jan 2013
Copyright © CodeProject, 1999-2014
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