![]() |
|
|
|||||||
![]() |
|
|
Thread Tools | Rate Thread |
|
|
PM User | #1 |
|
Regular Coder ![]() Join Date: Apr 2004
Posts: 575
Thanks: 10
Thanked 0 Times in 0 Posts
![]() |
Code to pull only up to a certain amount of chars..
I'm certain there is a function to do this but I forget what it is...
Say I am pulling values from the database, but I only want to pull like the first 10 chars of the value.. how do I do that? Thanks! |
|
|
|
|
|
PM User | #2 |
|
Regular Coder ![]() Join Date: Jun 2002
Location: UK
Posts: 577
Thanks: 0
Thanked 0 Times in 0 Posts
![]() |
SUBSTRING(str,pos)
SUBSTRING(str FROM pos) SUBSTRING(str,pos,len) SUBSTRING(str FROM pos FOR len) The forms without a len argument return a substring from string str starting at position pos. The forms with a len argument return a substring len characters long from string str, starting at position pos. The forms that use FROM are SQL-92 syntax. mysql> SELECT SUBSTRING('Quadratically',5); -> 'ratically' mysql> SELECT SUBSTRING('foobarbar' FROM 4); -> 'barbar' mysql> SELECT SUBSTRING('Quadratically',5,6); -> 'ratica' This function is multi-byte safe. from the manual, so 'SELECT (`field` FROM 0 FOR 10) AS `fld` FROM `table` WHERE 1'; should suffice. You might also check SUBSTRING_INDEX |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Rate This Thread | |
|
|