shane
shane

Reputation: 110

mysql SUBSTR() problem

Nice easy one for this morning.

Ok, here's my little sql statement

SELECT SUBSTR(quote,1,20) FROM b_quotes WHERE id='74'

This is returning an empty result which is confusing because if I call upon any other part of that record (the customers email address for example) it returns it perfectly. I've tried variations and it always seems to be the SUBSTR part that is failing.

could anyone shed some light on this?

Thanks Shane

Upvotes: 0

Views: 6211

Answers (3)

Brian Showalter
Brian Showalter

Reputation: 4349

Since you haven't indicated which data type is used for the quote column, try this:

SELECT SUBSTR(CAST(quote as CHAR),1,20) FROM b_quotes WHERE id='74'

Upvotes: 1

Alessandro
Alessandro

Reputation: 1336

What's the datatype of the quote column? If it's a CHAR or VARCHAR, what's its length? What code are you using to access the data returned from the database?

Your SQL statement is correct, so if you want to avoid workarounds and just want to know why your query doesn't seem to work (as you asked) you have to research problems in your application code.

Upvotes: 0

xzyfer
xzyfer

Reputation: 14135

Try SELECT SUBSTR(quote,1,20) AS q FROM b_quotes WHERE id='74'

Upvotes: 0

Related Questions