SQL SQL选择单词的第一个字母?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8856384/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 14:00:21  来源:igfitidea点击:

SQL select first letter of a word?

sqlsql-server-2005

提问by JNK

In SQL how do you select just the first letter?

在 SQL 中,如何只选择第一个字母?

For example if i have a column called ColumnX and it has the value of "hippodarts" how do I select just the letter H?

例如,如果我有一个名为 ColumnX 的列并且它的值为“hippodarts”,我如何只选择字母 H?

回答by JNK

To get the first letter of a STRINGyou can use left:

要获取STRING的第一个字母,您可以使用 left:

SELECT LEFT(ColumnX, 1)

SELECT LEFT(ColumnX, 1)

To do it for a wordwithin a string is more complicated.

对字符串中的单词执行此操作更为复杂。

回答by msarchet

Select LEFT(COLUMNX, 1) From Table

回答by dknaack

Description

描述

You can use the T-SQL function substringor left

您可以使用 T-SQL 函数substringleft

Sample

样本

Substring

子串

SELECT substring(ColumnX,1,1) FROM YOURTABLENAME

left

剩下

SELECT LEFT(ColumnX, 1) FROM YOURTABLENAME

More Information

更多信息

回答by Michael Berkowski

By using SUBSTRING()

通过使用SUBSTRING()

SELECT SUBSTRING(columnname, 1, 1) AS firstletter FROM tablename

回答by kwelch

SELECT LEFT(ColumnX,1) FROM Table

从表中选择 LEFT(ColumnX,1)

I hope this helps.

我希望这有帮助。

回答by bhamby

Another option!

另外一个选项!

SELECT CAST(your_col AS CHAR(1))
FROM your_table