Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Old 02-01-2005, 11:31 AM   PM User | #1
cyphix
Regular Coder

 
Join Date: Apr 2004
Posts: 575
Thanks: 10
Thanked 0 Times in 0 Posts
cyphix is an unknown quantity at this point
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!
cyphix is offline   Reply With Quote
Old 02-01-2005, 12:12 PM   PM User | #2
Ökii
Regular Coder

 
Join Date: Jun 2002
Location: UK
Posts: 577
Thanks: 0
Thanked 0 Times in 0 Posts
Ökii is an unknown quantity at this point
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
__________________
Ökii - formerly pootergeist
teckis - take your time and it'll save you time.
Ökii is offline   Reply With Quote
Old 02-01-2005, 12:49 PM   PM User | #3
cyphix
Regular Coder

 
Join Date: Apr 2004
Posts: 575
Thanks: 10
Thanked 0 Times in 0 Posts
cyphix is an unknown quantity at this point
Thanks Ökii!
cyphix is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:12 AM.

Home - Contact Us - Archives - Link to CF - Resources - Top 

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.