如何在 SQL Server 中选择前 100 个字符?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4280854/
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
How can I select the first 100 characters in SQL Server?
提问by Matt
I want to truncate a column to a max of 100 characters. How do you do this in SQL Server?
我想将一列截断为最多 100 个字符。你如何在 SQL Server 中做到这一点?
回答by Jasdeep Singh
Try this:
尝试这个:
SELECT LEFT (your_column, 100) FROM your_table
Edit:
编辑:
you can also try something like this:
你也可以尝试这样的事情:
SELECT LEFT (your_column, LEN(your_column)-5) FROM your_table
for say if you want to trim the last 5 characters from a record.
例如,如果您想修剪记录中的最后 5 个字符。
回答by Mike Caron
SUBSTRING(myColumn, 1, 100)
SUBSTRING(myColumn, 1, 100)
See the docs: http://msdn.microsoft.com/en-us/library/ms187748.aspx
请参阅文档:http: //msdn.microsoft.com/en-us/library/ms187748.aspx
回答by Jaykay
SELECT SUBSTR(COLUMN_NAME, 1, LENGTH) FROM TABLENAME where LENGTH(COLUMN_NAME) > LENGTH
Ex:
前任:
SELECT SUBSTR(DESCRIPTION,1,100) FROM STOREDETAILS where LENGTH(DESCRIPTION)>100
For those records, with length less than 100, the actual value would be shown.
对于那些长度小于 100 的记录,将显示实际值。
Otherwise, some databases induce blank characters in the resultant records.
否则,某些数据库会在结果记录中引入空白字符。
回答by MarcelDevG
substring is the method: SUBSTRING ( value_expression ,start_expression , length_expression ) from the help.
substring 是方法: SUBSTRING ( value_expression ,start_expression , length_expression ) 来自帮助。