Click here to Skip to main content
13,145,774 members (63,134 online)
Rate this:
Please Sign up or sign in to vote.
See more:

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"

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

1 solution

Rate this: bad
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.

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 |
Web01 | 2.8.170915.1 | Last Updated 7 Jan 2013
Copyright © CodeProject, 1999-2017
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