Solved

select a varchar row and display only the first 3 characters

Posted on 2013-11-05
5
210 Views
Last Modified: 2013-11-07
input
12345
abcde

output
123
abc
0
Comment
Question by:rgb192
  • 3
5 Comments
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 39623686
Do you want to use PHP or want to do in mysql itself?
0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 39623693
Using PHP try like this,

<?php

$myStr='12345';
$result = substr($myStr, 0, 3);
echo $result;
?>

Open in new window

0
 
LVL 10

Accepted Solution

by:
HuaMinChen earned 500 total points
ID: 39623696
Use
select substring(column1,1,3) from ...

Open in new window

0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 39623711
Try to do it with SQL substring() function. So that it selects only 3 char from the varchar column.
0
 

Author Closing Comment

by:rgb192
ID: 39629605
This was the easiest code to use.
Thanks.
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
A lot of articles have been written on splitting mysqldump and grabbing the required tables. A long while back, when Shlomi (http://code.openark.org/blog/mysql/on-restoring-a-single-table-from-mysqldump) had suggested a “sed” way, I actually shell …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now