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

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-17-2002, 06:10 PM   PM User | #1
BillL
New to the CF scene

 
Join Date: Jun 2002
Location: NY, NY
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
BillL is an unknown quantity at this point
Shortening Data

If you have the data in "column X" = NNGS0182 is there a way to run a query to just pull characters 2-5. (ngs0) or maybe even create a stored procedure to in insert NNGS0182 as NGS0.

Thanks
BillL is offline   Reply With Quote
Old 06-17-2002, 08:58 PM   PM User | #2
Jeewhizz
Regular Coder


 
Join Date: May 2002
Location: London, England
Posts: 369
Thanks: 0
Thanked 0 Times in 0 Posts
Jeewhizz is an unknown quantity at this point
The best way to do this is to probably use PHP before inserting teh data as you suggested. The code below will do that for you

PHP Code:
$string "NNGS0182";
$string substr($string14); 
For more info see www.php.net/substr

Jee
__________________
Jeewhizz - MySQL Moderator
http://www.sitehq.co.uk
PHP and MySQL Hosting
Jeewhizz is offline   Reply With Quote
Old 06-18-2002, 02:19 AM   PM User | #3
wabirdman
New Coder

 
Join Date: Jun 2002
Location: Australia
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
wabirdman is an unknown quantity at this point
You can do this using MYSQL

SELECT SUBSTRING('NNGS0182',2,4);


The layout is like this: SUBSTRING(str,pos,len)
You can find more about this at

http://www.mysql.com/doc/S/t/String_functions.html

Hope this helps
wabirdman
wabirdman is offline   Reply With Quote
Old 06-18-2002, 09:00 PM   PM User | #4
Jeewhizz
Regular Coder


 
Join Date: May 2002
Location: London, England
Posts: 369
Thanks: 0
Thanked 0 Times in 0 Posts
Jeewhizz is an unknown quantity at this point
True, but its easy to do this before you enter, otherwise it has to be truncated each time the page loads, and if you're alking 100's of hits, then its ading to server load

Jee
__________________
Jeewhizz - MySQL Moderator
http://www.sitehq.co.uk
PHP and MySQL Hosting
Jeewhizz is offline   Reply With Quote
Old 06-19-2002, 01:32 AM   PM User | #5
wabirdman
New Coder

 
Join Date: Jun 2002
Location: Australia
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
wabirdman is an unknown quantity at this point
Yes that is true. I normally use ORACLE, so I dont really worry that.

wabirdman
wabirdman is offline   Reply With Quote
Old 06-19-2002, 02:11 PM   PM User | #6
mordred
Senior Coder


 
Join Date: Jun 2002
Location: frankfurt, german banana republic
Posts: 1,848
Thanks: 0
Thanked 0 Times in 0 Posts
mordred is an unknown quantity at this point
Quote:
Originally posted by Jeewhizz
True, but its easy to do this before you enter, otherwise it has to be truncated each time the page loads, and if you're alking 100's of hits, then its ading to server load
That's only a valid concern if your assumptions about the use of that MySQL statement in context of the application is equal to what BillL thought of. In other words, only when you read out something for presentational display. Also, can you make sure that the "column X" is not used in other contexts where the full string of it's fields is needed? I mean, why should one devise it to store such a content if only a part if it would be actually needed.

I *suspect* that BillL *might* use it in an insert that relies on values retrieved by [..] JOIN statements. If that's the case, go with wabirdmans suggestion. So it's up to you BillL to clarify your question.

Last edited by mordred; 06-19-2002 at 08:16 PM..
mordred 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 05:21 PM.


Advertisement
Log in to turn off these ads.