Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: Shortening Data

  1. #1
    New to the CF scene
    Join Date
    Jun 2002
    Location
    NY, NY
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Regular Coder
    Join Date
    May 2002
    Location
    London, England
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #3
    New Coder
    Join Date
    Jun 2002
    Location
    Australia
    Posts
    81
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Regular Coder
    Join Date
    May 2002
    Location
    London, England
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #5
    New Coder
    Join Date
    Jun 2002
    Location
    Australia
    Posts
    81
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes that is true. I normally use ORACLE, so I dont really worry that.

    wabirdman

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •