Selecting a substring

  • Follow


SELECT * , SUBSTRING( `Reference` , (
LOCATE( "08", `Reference` ) ) AS TRACK
FROM `work`
WHERE `Reference` LIKE "%08-%"

This is giving me a syntax error. What's wrong?
0
Reply Derek 2/7/2011 1:25:19 PM

Derek Turner:

>SELECT * , SUBSTRING( `Reference` , (
>LOCATE( "08", `Reference` ) ) AS TRACK
>FROM `work`
>WHERE `Reference` LIKE "%08-%"
>
>This is giving me a syntax error. What's wrong?

The number of parentheses: 3x'(' and 2x')'

0
Reply Erick 2/7/2011 1:34:16 PM


On 7 Feb 2011 13:25:19 GMT, Derek Turner wrote:
> SELECT * , SUBSTRING( `Reference` , (
> LOCATE( "08", `Reference` ) ) AS TRACK
> FROM `work`
> WHERE `Reference` LIKE "%08-%"
>
> This is giving me a syntax error. What's wrong?

Some hints that might help you:

Don't use backtics around identifiers. I know a whole bunch of admin
type programs do that, but they do that because they're protecting
people from being morons in the simplest way they know how. If you're
not a moron, you won't need them at all because you'll be using
SQL-standard identifiers that are not reserved words to begin with.
Using backtics to mask that only leads to confusion and pain later.

Don't use " as a quoting mark. It is also not standard and standard is
perfectly adequate to express everything you'd need to express, so using
it will only serve to cause confusion and pain further down the road.

Finally, when asking what an error is, MySQL conveniently tells you
EXACTLY where it first realized that there was a problem in the part of
the error message that reads "check the manual that corresponds to your
MySQL server version for the right syntax to use near 'point_where_the
problem_is'". That "near 'point_where_the_problem_is'" is *THE MOST
IMPORTANT PART OF THE ERROR*. If you really want fast and precise help
from people instead of getting insults and mockery, you'll post the
entire error message when you get an error message.

-- 
94. When arresting prisoners, my guards will not allow them to stop and
    grab a useless trinket of purely sentimental value.
	--Peter Anspach's list of things to do as an Evil Overlord
0
Reply Peter 2/7/2011 1:49:53 PM

On 07-02-11 14:25, Derek Turner wrote:
> SELECT * , SUBSTRING( `Reference` , (
> LOCATE( "08", `Reference` ) ) AS TRACK
> FROM `work`
> WHERE `Reference` LIKE "%08-%"
> 
> This is giving me a syntax error. What's wrong?

you have 3 times a '('
and only 2 times a ')'

-- 
Luuk
0
Reply Luuk 2/7/2011 1:55:54 PM

On Mon, 07 Feb 2011 13:34:16 +0000, Erick T. Barkhuis wrote:

> Derek Turner:
> 
>>SELECT * , SUBSTRING( `Reference` , ( LOCATE( "08", `Reference` ) ) AS
>>TRACK FROM `work`
>>WHERE `Reference` LIKE "%08-%"
>>
>>This is giving me a syntax error. What's wrong?
> 
> The number of parentheses: 3x'(' and 2x')'

Thanks for the quick response, I looked and looked but couldn't see it :)

And now I've got the SUBSTRING syntax the right way round it even does 
what I want it to do!
0
Reply Derek 2/7/2011 2:14:23 PM

On 2/7/2011 9:14 AM, Derek Turner wrote:
> On Mon, 07 Feb 2011 13:34:16 +0000, Erick T. Barkhuis wrote:
>
>> Derek Turner:
>>
>>> SELECT * , SUBSTRING( `Reference` , ( LOCATE( "08", `Reference` ) ) AS
>>> TRACK FROM `work`
>>> WHERE `Reference` LIKE "%08-%"
>>>
>>> This is giving me a syntax error. What's wrong?
>>
>> The number of parentheses: 3x'(' and 2x')'
>
> Thanks for the quick response, I looked and looked but couldn't see it :)
>
> And now I've got the SUBSTRING syntax the right way round it even does
> what I want it to do!

The open parens in front of Reference does not have a corresponding 
closing parens.

Bill B
0
Reply Bill 2/7/2011 3:06:23 PM

5 Replies
165 Views

(page loaded in 0.05 seconds)

Similiar Articles:













7/15/2012 7:54:25 AM


Reply: