Solved

Can i order by JUST the first letter of a string in SQL?

Posted on 2008-06-13
2
224 Views
Last Modified: 2012-06-21
is it possible to order by only the first letter of a string in SQL?  for instance, here is my order by:

ORDER BY Silage_Corn_Hybrids_with_Same_Base_Genetics, dbo.parseInt(Silage_Corn_Relative_Maturity), Silage_Corn_Parent_Hybrid

and i have attached how my data is returning.  

i would like it to just display the 'F' Silage_Corn_Hybrids_with_Same_Base_Genetics first and the the 'T', but really sort by Silage_Corn_Relative_Maturity with the Silage_Corn_Parent_Hybrid family.

Is this possible?


F2F297	F2F297	90
F2F444	F2F444	102
F2F449	F2F444	104
F2F485	F2F485	98
F2F487	F2F485	99
F2F489	F2F485	99
F2F566	F2F566	105
F2F568	F2F566	105
F2F569	F2F566	105
F2F610	F2F610	108
F2F631	F2F631	110
F2F633	F2F631	110
F2F635	F2F631	110
F2F682	F2F682	112
F2F699	F697	113
F2F700	F697	113
F2F721	F2F721	113
F2F723	F2F721	113
F2F725	F2F721	113
F2F739	F2F739	113
F2F797	F2F797	115
F697	F697	112
TMF2H917	TMF2H917	123
TMF2H918	TMF2H917	123
TMF2L412	TMF2L412	92
TMF2L414	TMF2L412	92
TMF2L416	TMF2L412	94
TMF2L418	TMF2L412	94
TMF2L831	TMF2L831	118
TMF2L844	TMF2L844	119
TMF2M696	TMF2M696	110
TMF2N422	TMF2N422	94
TMF2N494	TMF94	        97
TMF2N602	TMF2N602	106
TMF2N804	TMF2N804	116
TMF2P719	TMF2P719	110
TMF2Q296	TMF2Q296	86
TMF2Q714	TMF2Q714	109
TMF2Q715	TMF2Q714	108
TMF2Q716	TMF2Q714	109
TMF2Q733	TMF2Q733	113
TMF2Q753	TMF2Q753	113
TMF2Q759	TMF2Q753	113
TMF2R521	TMF2R521	102
TMF2T497	TMF2T497	100
TMF2W583	TMF2W583	104
TMF2W587	TMF2W583	104
TMF2W726	TMF2W726	111
TMF94	        TMF94	        97

Open in new window

0
Comment
Question by:tarashea
[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
2 Comments
 
LVL 60

Accepted Solution

by:
chapmandew earned 500 total points
ID: 21781930
select * from tablename
order by left(fieldname,1)
0
 

Author Closing Comment

by:tarashea
ID: 31467048
excellent!  thanks a bunch!
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

710 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