I have the following data:
String
K40
I84
G401
M232
L72
And I am looking to obtain the following output
String
K40
I84
G40
M23
L72
Where those will a length of 4 are reduced by one. And those of length 3 are retained. The code I have used thus far is:
(left([string], len([string]) - 1))
However, this alters the string irrespective of length.
Using SQL Server 2008.
Many thanks
尝试这个:-
SELECT LEFT(YOUR_COLUMN, 3) FROM YOUR_TABLE;
SELECT SUBSTRING(YOUR_COLUMN, 1, 3) As AliasName from TableName
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.