I have tried to reference and use the follow examples that I have found:
http://sqlmag.com/t-sql/how-title-case-column-value
Like so:
V1:
SELECT DISTINCT upper(left(county,1))+lower(right(county,len(county)-1))
as county
FROM tablename
order by county
V2:
UPDATE tablename
SET county = UPPER(LEFT(county, 1)) + LOWER(RIGHT(county, LEN(county) - 1));
to avoid:
Having DISTINCT populate copies of text that are identical but are case sensitive [I have tested DISTINCT alone and it did in fact display the copies]
What I want to do is:
Display the text as sentence case for each distinct county value in database
Issue:
The issue I face is the fact that RIGHT
gives me an error of Invalid identifier
Is there a way to use my format but use a different value for RIGHT
?
Full chunk of VB.net coding to fill a dropdownlist:
If Not County_List Is Nothing Then
Dim County As OleDbCommand = New OleDbCommand("SELECT DISTINCT upper(left(county,1))+lower(right(county,len(county)-1)) as county FROM tablename order by county", conn)
Dim OracleDataAdapterAds3 As OleDbDataAdapter = New OleDbDataAdapter
OracleDataAdapterAds3.SelectCommand = County
Dim DsAds3 As DataSet = New DataSet
DsAds3.Clear()
If Not (DsAds3 Is Nothing) Then
OracleDataAdapterAds3.Fill(DsAds3, "tablename")
County_List.DataSource = DsAds3
County_List.DataMember = "tablename"
County_List.DataBind()
Dim newListItem As ListItem
newListItem = New ListItem("", "")
County_List.Items.Insert(0, newListItem)
County_List.SelectedIndex = -1
End If
End If
It looks like you are using Oracle. Oracle doesn't have LEFT()
and RIGHT()
. Instead, use SUBSTR()
:
SELECT DISTINCT upper(substr(county, 1, 1)) || lower(substr(county, 2)) as county
FROM tablename
ORDER BY county;
However, you might find INITCAP()
(see documentation) more to your liking:
select distinct initcap(county) as county
from tablename
order by county;