So I have two columns. One containing a prefix (nvarchar), and the next containing an nvarchar I wish to remove said prefix from, we'll name said column 'words'. Normally going right(words, len(words) - len(prefix)
would get me that answer. However let's say there is two spaces at the beginning of words and the prefix is a single space. So I'm trying to remove just one space from the beginning of the word. len(prefix) will return 0. datalength(prefix) will return 1 however due to some characters taking 2 bytes, I don't believe datalength to be the answer.
问问题
4496 次
2 回答
6
尝试这个 :
RIGHT(words, LEN(words) - (LEN(prefix+'?')-1))
编辑:
也许你会发现这个“更干净”:
RIGHT(words, LEN(words) - DATALENGTH(CONVERT(VARCHAR(100),prefix)))
于 2013-10-09T18:44:34.833 回答
1
CASE WHEN CHARINDEX(prefix,words) = 1 THEN RIGHT(words, LEN(words) - LEN(prefix)) ELSE words END
这确保前缀从开头开始,而不是在单词的中间或任何地方。
于 2019-05-22T22:01:51.133 回答