在 SQL Server 中的文本字段上使用 LEFT
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1513852/
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
Using LEFT on a TEXT-field in SQL Server
提问by Kjensen
In a table, I have a text-field. I need to be able to select only the first 200 chars of the field - but LEFT does not work with TEXT-fields.
在表格中,我有一个文本字段。我只需要能够选择该字段的前 200 个字符 - 但 LEFT 不适用于文本字段。
What to do?
该怎么办?
回答by anishMarokey
回答by marc_s
You cannot apply string manipulation functions on TEXT fields - you should stop using TEXT anyway, since it will be removed from SQL Server soon!
你不能在 TEXT 字段上应用字符串操作函数 - 你应该停止使用 TEXT,因为它很快就会从 SQL Server 中删除!
What you can do is convert your TEXT column to VARCHAR(MAX) And then use the string gfunction:
您可以做的是将您的 TEXT 列转换为 VARCHAR(MAX) 然后使用字符串 gfunction:
SELECT LEFT(CAST(YourTextCol AS VARCHAR(MAX), 200) .....