Click here to Skip to main content
15,897,360 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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
Comments
Jibesh 7-Jan-13 13:46pm    
Are you using a stored procedure?
Ashy-G 8-Jan-13 7:52am    
yes

1 solution

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
SQL
IF @id LIKE "#STA%"
and any string that begins with "#STA" would mean "DO SOMETHING" is executed.
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900