我试图引用并使用我发现的以下示例:
http://sqlmag.com/t-sql/how-title-case-column-value
像这样:
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));
要避免:
让DISTINCT填充相同但区分大小写的文本副本[我单独测试了DISTINCT并且确实显示了副本]
我想做的是:
将数据显示为数据库中每个不同县值的句子大小写
问题:
我面临的问题是RIGHT
错误 Invalid identifier
有没有办法使用我的格式,但为RIGHT
使用不同的值?
完整的VB.net编码以填充下拉列表:
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
答案 0 :(得分:1)
看起来您正在使用Oracle。 Oracle没有LEFT()
和RIGHT()
。相反,请使用SUBSTR()
:
SELECT DISTINCT upper(substr(county, 1, 1)) || lower(substr(county, 2)) as county
FROM tablename
ORDER BY county;
但是,您可能会根据自己的喜好找到INITCAP()
(请参阅documentation):
select distinct initcap(county) as county
from tablename
order by county;