Solved

select a varchar row and display only the first 3 characters

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

output
123
abc
0
Comment
Question by:rgb192
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 11

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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

705 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