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
SQL select first letter of a word?
提问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 substring
or left
您可以使用 T-SQL 函数substring
或left
Sample
样本
Substring
子串
SELECT substring(ColumnX,1,1) FROM YOURTABLENAME
left
剩下
SELECT LEFT(ColumnX, 1) FROM YOURTABLENAME
More Information
更多信息
回答by Michael Berkowski
回答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