SqlServer gets the sql statement of lowercase letters in a string
Sometimes we will intercept some special things in the string, such as uppercase and lowercase letters, module numbers, Chinese characters, numbers, and so on. Today, we will introduce a way to get lowercase letters (also uppercase letters) in a string.
DECLARE @ s VARCHAR (MAX) = 'AbcdEf Ool'-string to be intercepted DECLARE @ temp VARCHAR (MAX) =''- temporary variable SELECT @ temp=@temp+SUBSTRING (ch, sv.number, 1) FROM (SELECT @ s AS ch) t CROSS APPLY [master] .dbo.spt _ values AS sv WHERE sv.type = 'P'AND sv.number BETWEEN 1 AND LEN (ch) AND ASCII (SUBSTRING (ch, sv.number) 1) BETWEEN ASCII ('a') AND ASCII ('z') SELECT @ temp
The results are as follows:
So we get lowercase letters, and of course we can get uppercase letters:
SELECT @ temp=@temp+SUBSTRING (ch, sv.number, 1) FROM (SELECT @ s AS ch) t CROSS APPLY [master] .dbo.spt _ values AS sv WHERE sv.type ='P' AND sv.number BETWEEN 1 AND LEN (ch) AND ASCII (SUBSTRING (ch, sv.number, 1) BETWEEN ASCII ('A') AND ASCII ('Z') SELECT @ temp
The results are as follows:
Flexible grasp, according to the needs of the application.
Summary
The above is the realization sentence of SqlServer to get the lowercase letters of the string introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to the website!